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)
 Query - Copy row into another table

Author  Topic 

zaidiwaqas
Starting Member

8 Posts

Posted - 2009-05-21 : 03:05:26
hi,

any idea how to make the query that can pick all the fields from one table and copy it to the second.

i have two tables. TB_MAIN and other is TB_HISTORY.
when an update happens in TB_MAIN (through a code i am writing), i want the whole record to move the second table TB_HISTORY.

ex.

insert into TB_HISTORY values (select * from TB_MAIN where no = 1)
this is not the correct syntax cos is returning error.

note: i don't want to write each and every column in the query as there are around 120 columns.

any help or any other way out.

Regards,
Zaidi

zaidiwaqas
Starting Member

8 Posts

Posted - 2009-05-21 : 03:12:45
oh h. found the mistake.....


not to include "values ()"

correct syntax
insert into TB_HISTORY select * from TB_MAIN where no = 1
Go to Top of Page
   

- Advertisement -