sql sever建立
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql sever建立相关的知识,希望对你有一定的参考价值。

创建时NOT NULL 限制非空
PRIMARY KEY 该字段为主键
DEFAULT ‘男‘ 设默认值为“男”
CONSTRAINT 约束名 CHECK (条件)



注意这里外键和主键放在最后面。




(1)新增加字段时可以同时设置空值约束、默认值约束和标识列。
(2)表中的列名必须唯一
(3)若不允许为空时则必须给新增加的列指定默认值,否则语句执行错误
ALTER TABLE 只允许添加满足下述条件的列: 列可以包含空值;或者列具有指定的DEFAULT 定义;或者要添加的列是标识列或时间戳列;或者,如果前几个条件均未满足,则表必须为空以允许添加此列。




为约束起名,便于引用



注意外键的值要存在











以上是关于sql sever建立的主要内容,如果未能解决你的问题,请参考以下文章