及求缺省
實現對一個列增加 如: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;