Swim in SQL server

How to insert Identity value in a table?
/*
In the below example we have single Identity column table. Using with "Default Values" we can insert the values into table.
*/
create table #tbl(id int identity)
go

insert into #tbl default values
go 10

select * from #tbl
go

drop table #tbl
go

____________________________________________________________________________________________
CREATE TABLE #TBL1(ID INT IDENTITY , NAME VARCHAR(10) NULL , COUNTRY VARCHAR(10) DEFAULT 'INDIA')
go

INSERT INTO #TBL1 DEFAULT VALUES
GO 10

SELECT * FROM #TBL1
go

drop table #TBL1
go

/*
Here the ID is Identity column , Name will allow the nulls and Country Default value is 'India'.
*/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: