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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Select statement to insert data into table

Author  Topic 

mk_garg20
Constraint Violating Yak Guru

343 Posts

Posted - 2004-08-08 : 21:34:21
Hello All,
Here in posts, i have seen statements like this to insert data into table.

INSERT INTO myTable99([ID], [date], value)
SELECT 1, '1/4/2004', 100 UNION ALL
SELECT 2, '2/4/2004', 10 UNION ALL
SELECT 3, '2/4/2004', 90

Mostly i use statements like
INSERT INTO myTable99 values(1, '1/4/2004', 100)
INSERT INTO myTable99 values(2, '2/4/2004', 10)
INSERT INTO myTable99 values(3, '2/4/2004', 90)

What is benefit of using select statements to insert data:-
Easy syntax or any other reason as well.

Thanks
Manoj

timmy
Master Smack Fu Yak Hacker

1242 Posts

Posted - 2004-08-08 : 21:52:46
The first option only needs one trip to the database. The second one needs 3.
I think that the second option is more readable, but I suppose it's personal preference....
I use it most of the time to insert testing data and for debugging stuff, so performance isn't really an issue.

Go to Top of Page
   

- Advertisement -