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)
 Sql queries

Author  Topic 

venki8805
Starting Member

3 Posts

Posted - 2009-06-29 : 16:16:04
Hi ,
I am having a doubt on queries,plz tell me the solution for the below query.
write a single query To delete a column from table1 and add the same deleted column of table1 to table2 and has to display the added column in the table2.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-29 : 16:20:03
ALTER TABLE Table2 ADD COLUMN ColX INT
GO

UPDATE t2
SET t2.ColX = t1.ColX
FROM Table2 AS t2
INNER JOIN Table1 AS t1 ON t1.pkCol = t2.pkCol
GO

ALTER TABLE Table1
DROP COLUMN ColX
GO



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

venki8805
Starting Member

3 Posts

Posted - 2009-06-30 : 09:43:38
Its working fine.thanks for posting answer to my query
Go to Top of Page

ayamas
Aged Yak Warrior

552 Posts

Posted - 2009-06-30 : 10:15:11
Also have a look at the new output deleted clause of SQL 2005

DELETE FROM table1
OUTPUT DELETED.* INTO table2
Go to Top of Page
   

- Advertisement -