Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to add column in a table from one database to another database in sql server

please help me
Posted
Updated 23-Nov-13 0:13am
v2

First step would be add the column using an Update Table query.
Second step would be to copy data from first tables column to another.
 
Share this answer
 
Assume that your source table and target table is same and both database are in same sql server instance. If so then you add column with same data-type which you import from source table.

SQL
alter table add NewColumnName int null;


then need to update that table with update query with join
SQL
update TargetTable set
 MyNewColumnName = T.SourceColumn
FROM SourceDatabase.schema.SourceTable AS T
inner join TargetTable ON TargetTable.PrimaryKey = T.PrimaryKey;


If your source and target database is in 2 differet sql server instance/network then you just need to create a link server to your target database and use that linkserver reference to the update query.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900