create table tb1(a varchar)
alter table tb1 add b varchar null
alter table tb1 alter column a varchar not null
alter table tb1 add constraint pk_主键约束 primary key(a)
insert into tb1 values('a',null)
insert into tb1 values('b',null)
insert into tb1 values('c',null)
insert into tb1 values('d',null)
insert into tb1 values('e',null)
update tb1 set b=m.b from tb1,(select a,b=row_number() over (order by a) from tb1) m where tb1.a=m.a //a列不能有重复值
select * from tb1
alter table tb1 add b varchar null
alter table tb1 alter column a varchar not null
alter table tb1 add constraint pk_主键约束 primary key(a)
insert into tb1 values('a',null)
insert into tb1 values('b',null)
insert into tb1 values('c',null)
insert into tb1 values('d',null)
insert into tb1 values('e',null)
update tb1 set b=m.b from tb1,(select a,b=row_number() over (order by a) from tb1) m where tb1.a=m.a //a列不能有重复值
select * from tb1
本文演示了如何使用SQL语句创建表、添加字段、设置主键约束并填充数据。通过具体实例展示了表结构修改、数据插入及更新操作。
529

被折叠的 条评论
为什么被折叠?



