Default values in microsoft Sql Server
-
I would like to specify a default value for a column that increments along with the row number/identity column. i.e. Insert tbl_User (some_data) VALUES (test) resulting in
User_id first_name last_name some_data
1 Test User 1 testI was sure there was something like @@row_number, but searching on msdn/google has turned up nothing useful so far... Any suggestions? Thanks, Al
-
I would like to specify a default value for a column that increments along with the row number/identity column. i.e. Insert tbl_User (some_data) VALUES (test) resulting in
User_id first_name last_name some_data
1 Test User 1 testI was sure there was something like @@row_number, but searching on msdn/google has turned up nothing useful so far... Any suggestions? Thanks, Al
Set your default value to something like
'Test' + CAST(DATEPART(second, GETDATE()) AS VARCHAR)
or for more randomness'Test' + CAST(DATEPART(second, GETDATE()) AS VARCHAR) + CAST(DATEPART(ms, GETDATE()) AS VARCHAR)
You'll get fairly random data, not entirely unique though.SG Cause is effect concealed. Effect is cause revealed.
-
Set your default value to something like
'Test' + CAST(DATEPART(second, GETDATE()) AS VARCHAR)
or for more randomness'Test' + CAST(DATEPART(second, GETDATE()) AS VARCHAR) + CAST(DATEPART(ms, GETDATE()) AS VARCHAR)
You'll get fairly random data, not entirely unique though.SG Cause is effect concealed. Effect is cause revealed.
Thanks - perfect for what I need! :-D
-
I would like to specify a default value for a column that increments along with the row number/identity column. i.e. Insert tbl_User (some_data) VALUES (test) resulting in
User_id first_name last_name some_data
1 Test User 1 testI was sure there was something like @@row_number, but searching on msdn/google has turned up nothing useful so far... Any suggestions? Thanks, Al
use sonia create table stud(roll int identity(10,2),name varchar) insert into stud values('A') insert into stud values('B') select * from stud **IDENTITY(10,2) --> 10 is the initial value 2 is the number by which the value is to be incremented. U can also decrement the value.