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
 Inserting manually more values into a table

Author  Topic 

sangoku
Starting Member

19 Posts

Posted - 2009-09-01 : 13:56:28
Hello I am relatively new to SQL server and i need help for a seminar work i need to insert into a table more values at once, i know it is possible but dont know how.

I usually use the standard query
INSERT INTO 'name of the table'
(rows which are inserted)
VALUES
(values)

How can i insert more rows at once????

while earth still spining
live on, have fun
else
move to mars

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-09-01 : 14:09:38
if you can can select the rows to be inserted from another table.you can use it like

INSERT INTO <table> (field1,field2,field3)
SELECT field1,field2,field3 from <2ndtable> WHERE <urcondition>

if you need to insert hard-coded value..you can use 'union all' like below

declare @t table ([name] varchar(20),in_time datetime, out_time datetime)
insert @t
select 'Alex', '2008-08-12 08:00', '2008-08-12 16:00' union all
select 'Alex', '2008-09-12 08:00', '2008-09-12 16:00' union all
select 'Alex', '2008-10-12 09:00', '2008-10-12 17:00' union all
select 'George', '2008-08-12 08:00', '2008-08-12 16:00' union all
select 'George', '2008-09-12 08:00', '2008-09-12 16:00' union all
select 'George', '2008-10-12 16:00', '2008-10-12 22:00'
Go to Top of Page

sangoku
Starting Member

19 Posts

Posted - 2009-09-01 : 14:26:10
Sorry, it seems i am not understanding you right.
The first case is not a option i need to insert the values manually.

The second:

are you declaring a temp table and then inserting the values here or can i insert it directly into my table?


EDIT

ok ok i get it thy that was an example thy
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-09-01 : 14:30:06
Yes..that was just an example..you can do the same with your table.
Go to Top of Page

sangoku
Starting Member

19 Posts

Posted - 2009-09-01 : 14:35:23
[quote]Originally posted by sangoku

Ok i get the picture now but i need to specify the exact rows which are to be inserted the rest is filed via default value like

INSERT Diskusije
(IdPorijekla,ZadnjiKomentar, Postavljac,Nastao, ImeDiskusije, OpisDiskusije)
VALUES
(
1,
GETDATE(),
'Administrator',
GETDATE(),
'<h1>Main-Glavni Meni</h1>',
'Ovdje se nalaze sve glavne dikusije'
)

how can i specify by your method which values will be inserted?

DAMN again edit the statmen gous trough like nothing with the rows defined thy again for the help i got it now

while earth still spining
live on, have fun
else
move to mars
Go to Top of Page
   

- Advertisement -