create table t(
name varchar(10),
age int
)
10为字符长度
修改表
***修改列名
alter table t change column name uname varchar(11);
***修改列类型
alter table t modify column name int;
***增加列
alter table t add column city varchar(11);
***删除列
alter table t drop column city
***修改表名
alter table t rename to ta;
删除表
drop table if exists t
复制表
***不含数据
create table tb like t;
***含数据
create table tb select * from t;
***部分字段及数据
create table tb select name from t where id=1;
not null
default
unique
primary key
check
foreign key
***列级约束
foreign key无效果
***表级约束
not null
default
无效果
建表添加约束
***列级
create table t(
id int primary key;
age int not null;
name varchar(10) unique;
money int default 250;
)
***《show index from t查看表索引》
***表级
create table t(
CONSTRAINT [name] FOREIGN KEY(id) REFERENCES t2(id);
constraint [name] unique(age);可以为空,且多个
constraint [name] primary key(age,name);
一个且非空,联合主键
默认约束名为字段名
)