当前位置: 代码迷 >> Sql Server >> 及求缺省解决方法
  详细解决方案

及求缺省解决方法

热度:69   发布时间:2016-04-27 17:32:51.0
及求缺省
實現對一個列增加   如:PQ00001

------解决方案--------------------

CREATE TABLE [dbo].[Table1] (
[sn] [int] IDENTITY (1, 1) NOT NULL ,
[col1] AS ( 'PQ ' + replicate( '0 ',10-len(sn))+cast(sn as varchar)),
[col2] [char] (10)
)
go
--create trigger tr_1 on table1 for insert as update table1 set col3= 'PQ ' + replicate( '0 ',(10 - len(table1.sn))) from inserted where table1.sn=inserted.sn
go
insert into table1(col2)
select 'b '
union all select 'c '
union all select 'c '
union all select 'c '
union all select 'c '
union all select 'c '
union all select 'c '
union all select 'c '
union all select 'c '
union all select 'c '
union all select 'c '
union all select 'c '
union all select 'c '
go
select * from table1;
  相关解决方案