1. -- 建表模板
    2. -- 外键表
    3. create table key_test
    4. (
    5. id int auto_increment,
    6. bh int not null unique,
    7. constraint primary key pid(id desc )#指定使用倒序排列
    8. );
    9. drop table key_test;
    10. alter table key_test add name1 varchar(20) comment '名称';
    11. alter table key_test drop name1;
    12. alter table key_test alter column name1 varchar(20);#有些数据库无法使用
    13. select * from key_test order by id desc ;#倒序排列
    14. insert into key_test(bh) values (12),(13),(14),(15),(16),(17),(18),(19),(20),(21),(22);
    15. create table test_creat
    16. (
    17. id int,
    18. for_key int comment '外键,参照表key_test',
    19. name varchar(20) unique not null comment '学生姓名',
    20. age int comment '年龄' check (age>0 and age <100 ),
    21. sex char(2) check ( sex = '男' or sex= '女'),
    22. address varchar(60) comment '家庭住址',
    23. primary key pid(id),
    24. foreign key fid(for_key) references key_test(id),
    25. constraint id_check check ( id is not null)
    26. # constraint primary key pt_id(id),
    27. # constraint foreign key f_key(for_key) references key_test(id)
    28. );
    29. drop table test_creat;