Record
1.约束
1.1unique
- 唯一,可以为null
1.2not null
- 初始化时候不为NULL
values('', 5)
values(null, 5)
是不同的
1.3check
- id int check (id > 0)
- name nvarchar(30) check (name in(‘华’, ‘为’))
1.4default 默认值
1.5 primary key
- 插入的值,相应的primary key没有的时候,不能插入!—除非插入的值是null
- delete primary key的时候,要在建立外键的时候 设置 级联删除还是拒绝删除
1.5.2 复合主键
primary key(id, name)
1.6 foreign key
- 当有外键的时候不可以删除
2.表的修改
alter table ... add column ...
alter table ... alter column ... type ...
alter table ... alter column rename ... to ...
alter table ... drop column ... restrict
alter table ... rename to ...
Think
- null 与 空字符串区别
对于varchar,都不占用任何空间
对于char,null和‘’都占用空间,取决于char的初始大小 - 行级定义和表级定义