sqlserver为已存在的表添加主键和索引默认值

添加主键

alter table 表名 add  主键列名 int identity(1,1) primary key --主键列名不存在时-

alter table 表名 add constraint  主键名(主键名字不能重复) primary key(主键列名)        --主键列明存在时-

添加默认值

alter table 表名 add  默认名(不能重复) default(getdate()) for 默认值列名 ;

添加索引  非聚集

create nonclustered index  索引名(不能重复) on 表名 (索引列名)

 

查询连个字段完全相同的表

select * from a union all select * from  b 

你可能感兴趣的:(sqlserver为已存在的表添加主键和索引默认值)