
alter table Test
add constraint PK_Id primary key (Id)
--检查约束
alter table Test
add constraint CK_Name check(Name like '_')
--建表,并加主键约束。与自动增长列
if exists(select name from sysobjects where name = 'Test')
drop Table Test
go
create table Test
(
Id int primary key identity(1,1) not null,
Name varchar(10)
)
上面一位朋友好像有语法错误.
2、然后我们通过alter table语句来给表添加一个列
3、回到数据表一会我们看到列已经被添加进数据表了,但是默认值却没有
4、接下来我们在添加列的时候同时添加上默认值,这个时候运用default关键字
5、然后回到数据表,我们就看到默认值有内容了
6、另外在数据表中经常使用的是uniqueidentifier类型,这种字段设置默认值需要按如下图所示的方式进行
7、回到数据表中我们可以看到默认值已经添加上了一列
alter table 表名 add 列名 类型长度 [默认值] [是否可为空]alter table TABLE ADD F1 VARCHAR(100) DEFAULT 'A' NOT NULL
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)