---创建主键约束,唯一约束,检查约束
create table test
(
id int,
testname varchar(50),
sex bit,
class varchar(50),
score float default(0)
constraint pk_test primary key/*这里可以指定是创建聚集或非聚集索引clustered|nonclustered可选项*/(id)
constraint ix_test unique(testname)
constraint ck_test check/*这里可以使用 not for replication可选项,用于指定当从其他表中复制数据时,不检查约束条件*/(score>=0)
)
go
create table test
(
id int,
testname varchar(50),
sex bit,
class varchar(50),
score float default(0)
constraint pk_test primary key/*这里可以指定是创建聚集或非聚集索引clustered|nonclustered可选项*/(id)
constraint ix_test unique(testname)
constraint ck_test check/*这里可以使用 not for replication可选项,用于指定当从其他表中复制数据时,不检查约束条件*/(score>=0)
)
go
用一楼的方式,如果建表了,用alter table xxx add 命令
在建表时加:
create table table_name
(
字段1,
字段2,
primary key (字段1)
)在建表后加:alter table table_name add constraint pk_name primary key(列名)
可以根据该行的唯一值字段检索到该行([过滤条件]),然后更新即可. update [表名] set 字段=[值] where [过滤条件]
比如我有下面的一列 要对第三个位置的元素进行赋值修改
ab
1
11
22
33
....
其中ab是列名 对第三个值22进行赋值 那这个where后面的过滤条件怎么写