Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to insert data in sql server

Author  Topic 

sandip.mondal
Starting Member

1 Post

Posted - 2011-12-16 : 03:56:45
Please define how to insert data in sql server

sandip kumar mondal

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2011-12-16 : 04:21:38
insert into <table>
select from <table>

or from a flat file, use bcp or bulk insert

you can also use osql as well as ssis, dts (if pre-2005) as well as other third party methods.

Now, what exactly were you after?
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2011-12-16 : 06:25:49
Or better still (it protects you from column ordinal changes / development )

INSERT INTO <table> (COLUMN LIST)
SELECT (COLUMN LIST) FROM <...>


Or if you want to insert static values

INSERT INTO <table> (COLUMN LIST)
VALES (val1,val2,val3....valn),(val1,val2,val3....valn)....


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-16 : 06:29:13
quote:
Originally posted by Transact Charlie

Or better still (it protects you from column ordinal changes / development )

INSERT INTO <table> (COLUMN LIST)
SELECT (COLUMN LIST) FROM <...>


Or if you want to insert static values

INSERT INTO <table> (COLUMN LIST)
VALES (val1,val2,val3....valn),(val1,val2,val3....valn)....



Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION



You can use the above format from sql 2008 onwards

for below version use modified suggestion below



INSERT INTO <table> (COLUMN LIST)
SELECT val1,val2,val3....valn UNION ALL
SELECT val1,val2,val3....valn....


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2011-12-16 : 06:41:19
cheers!

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page
   

- Advertisement -