Insert statement: Auto Increment with Version Number and Datetime

Hi Friends,

I have a table with 2 columns Version and CurrentDateTime

For every insert the Records should be Autoincrement for Version Column and Record Insertdatetime for that Version
1.0 | 2015-11-12 10:01.23..
2.0 | 2015-11-12 10.02.11..


You can set identity for version like identity(1,1) and default value for datetime column like getdate() along with other columns.
Make sure you have more than 2 columns in your table because u can't automate all the columns except using triggers.


Can you just give me the query ?

What is your table definition? As @subhaoviya said you need more than two columns.

And which version of SQL Server are you using?

create table tbl
    Version        int identity(1,1),
    CurrentDateTime    datetime default getdate()

insert into tbl values (default)
insert into tbl values (default)

select    *
from    tbl

drop table tbl
1 Like