数据定义语句(DDL)

数据定义语言
库和表的管理

一、库的管理

  1. 库的创建
    create database 【if not exists】库名;
  2. 库的修改
    更改库名:rename database 库名 to 新库名
    更改库的字符集:alter database 库名 character set 字符集
  3. 库的删除
    drop database [if exists] 库名

二、表的管理

  1. 表的创建
    列名  列的类型【(长度)约束】,
    列名 列的类型【(长度)约束】,
    ...
    列名 列的类型【(长度)约束】)
  1. 表的修改
  • 修改列名
    alter table 表名 change column 列名 新列名 类型
  • 修改列的类型或约束
    alter table 表名 modify column 列名 类型
  • 添加新列
    alter table 表名 add column 列名 类型
  • 删除列
    alter table 表名 drop column 列名
  • 修改表名
    alter table 表名 rename to 新表名
  1. 表的删除
    drop table 【if exists】表名
  2. 表的复制
  • 仅复制表的结构:create table 表名 like 表名
  • 复制表的结构加数据create table 表名 select * from 表名;
  • 复制部分数据select table 表名 select 列名.. from 表名 where 筛选条件
  • 仅复制部分字段create table 表名 select 列名... from 表名 where 永假条件
原文地址:https://www.cnblogs.com/ylcc-zyq/p/13139301.html