对一个数据列建立的约束,称为列级约束。
对多个数据列建立的约束,称为表级约束.
列级约束既可以在列定义时声明,也可以在列定义后声明.
表级约束只能在列定以后声明.
sql命令补充:
alter table `biao` add lieming varchar(20) after liedehoumian; //修改列
alter table `biao` drop lieming,drop lieming //删除列
alter table `biao` add constraint yueshuming_id primary key(id); //修改约束
alter talbe `biao` add unique(lieming);
show create table `biao`; //显示创建表的sql语句
show indexes from biao\G; //显示表的索引
alter table biao2 add foregin key(pid) references biao1(id);//添加外键
alter talbe biao alter age set default 15; //修改列的信息
alter table 表名 character set utf8 collate utf8_unicode_ci; //修改表的字符集
alter database 数据库名 character set utf8 collate utf8_unicode_ci; //修改表的字符集
alter table 表名 auto_increment = 1;//把表的自增长id清零
alter table table_name rename table_new_name; //改表的名字
show columns from 表名;//显示表的结构
ALTER TABLE `b` CHANGE `sex` `sex` ENUM( '男', '女' ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL;
//修改字段
查询数据库中所有表名
select table_name from information_schema.tables where table_schema='csdb' and table_type='base table';
查询指定数据库中指定表的所有字段名column_name
select column_name from information_schema.columns where table_schema='csdb' and table_name='users'