时间:2021-07-01 10:21:17 帮助过:11人阅读
1.设置表的列不能为null
alter table run.dbo.T1 alter column Col1 int not null
2.给表添加主键
alter table run.dbo.T1 add constraint pk_name primary key (Col1)
3.查看表中的列是否有重复数据
select count(*) as cnt,Col1 from run.dbo.T2 group by Col1 having count(*) >1
4.创建联合主键
create table testprim (id int not null,custid nvarchar(20) not null,name nvarchar(10),age int)
--id和custid组合起来的主键,主键的名称是pk_name
alter table run.dbo.testprim add constraint pk_testprim primary key (id,custid)
11-常用SQL总结
标签:name 重复数 sel column group -- char add test