-- Use trigger to insert the primary key value -- use a time variable to determine the primary key value create trigger SS on testinstead of insert -- execute this triggerasbegindeclare @ index varchar (30) before insertion) -- declare the variable waitfor delay '00: 00: 8080' -- executes the next instruction set @ Index = Replace (replace (convert (varchar (23 ), getdate (), 121 ),'-',''),'',''),':',''),'. ', '') -- converts the current time to the string insert into test select @ index, I. sname, I. status, I. city from inserted iendinsert into test (sname, status, city) values ('11', 30, 'ss'); insert into test (sname, status, city) values ('11', 30, 'ss'); insert into test (sname, status, city) values ('11', 30, 'ss '); insert into test (sname, status, city) values ('11', 30, 'ss'); insert into test (sname, status, city) values ('11 ', 30, 'ss'); insert into test (sname, status, city) values ('11', 30, 'ss'); drop trigger SS; delete from testselect * from test -- Test variable usage declare @ A numericset @ A = cast (replace (convert (varchar (23), getdate (), 121 ),'-',''),'',''),':',''),'. ', '') as numeric) print @ aprint convert (varchar, (@ A + 1) -- another method is to use the variable declare @ index varchar (30) -- declare the variable set @ Index = Replace (replace (convert (varchar (23), getdate (), 121 ),'-',''),'', ''),':',''),'. ', '') -- converts the current time to the string print @ Index