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 2005 Forums
 Transact-SQL (2005)
 import tables

Author  Topic 

Exir
Posting Yak Master

151 Posts

Posted - 2009-09-16 : 01:28:28
Is there any command to import a table with its datas in it? or the only way is createing the table and insert rows one by one?
i have no access to sql and i can only execute query on database

waterduck
Aged Yak Warrior

982 Posts

Posted - 2009-09-16 : 01:58:04
try select into


Hope can help...but advise to wait pros with confirmation...
Go to Top of Page

Exir
Posting Yak Master

151 Posts

Posted - 2009-09-16 : 02:10:30
quote:
Originally posted by waterduck

try select into


Hope can help...but advise to wait pros with confirmation...



I think this command if for importing when the table is already exists, but i want to import a table, like when we attach or restore a new database. is it possible ?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-16 : 02:18:39

Select * into new_table from old_table

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Exir
Posting Yak Master

151 Posts

Posted - 2009-09-30 : 01:32:43
This command inserts content of table1 into table2, which the table2 shouldnt be exists in the database, what about if i want to insert content of table1 to a table which exists in my database and is not same as table1, just want two column of these tables be same. is it possible to have bulk insert? for example like insert column1 of table1 to column1 of table2 where column2 of table1= column2 of table2 ?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-09-30 : 01:38:13
do you mean this?

UPDATE t1
SET t1.col1=t2.col1
FROM table1 t1
INNER JOIN table2 t2
ON t2.col2=t1.col2
Go to Top of Page

Exir
Posting Yak Master

151 Posts

Posted - 2009-09-30 : 01:56:24
my table1 is exactly same as t2 just a column of table2 defined as PK and its identity specification is true, so i want insert all the content of columns in table1 into table2 without any condition.
How can i do this ?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-30 : 02:03:18
UPDATE t1
SET t1.col1=t2.col1
FROM table1 t1
INNER JOIN table2 t2
ON 1=1

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Exir
Posting Yak Master

151 Posts

Posted - 2009-09-30 : 02:05:46
Dear Mahdaivanan
my table2 is empty, i think i have to write insert command, yes ?
should i insert row by row manually like "INSERT INTO table1(cilumn) VALUES ('value1')" or i can have bulk insert ?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-30 : 02:24:36
Insert into table2(columns)
select columns from table1

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Exir
Posting Yak Master

151 Posts

Posted - 2009-09-30 : 02:38:42
yesss, it works, thanks alot
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-30 : 05:17:21
quote:
Originally posted by Exir

yesss, it works, thanks alot


You are welcome

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -