DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
SITE SEARCH SQLUSA.com HEADLINES NEWS
SQL E/BOOKS   SQL 2014 PROGRAMMING   DOWNLOADS
SCRIPTS SQL 2005 SQL 2008 ARTICLES
SQL JOBS TWITTER FORMAT VIDEOS
How to update from a different database?

Execute the following SQL Server T-SQL script in SSMS Query Editor to demonstrate how to update the product names in the Product table from a different database using 3-part naming (referencing):

USE tempdb;

-- Create test table with SELECT INTO  

SELECT * INTO Product

FROM AdventureWorks.Production.Product

 

-- Blank out product name

 

UPDATE Product SET Name=''

 

SELECT * FROM Product

 

-- Update product name

-- by using 3-part reference to access other database table

UPDATE P SET P.[Name]=AWP.[Name]

FROM Product P

JOIN AdventureWorks.Production.Product AWP

ON AWP.ProductID=P.ProductID;

 

SELECT * FROM Product

 

USE tempdb;

DROP TABLE Product

GO

---------- 

 

Related articles:

 

Mastering the SQL UPDATE Syntax

 

UPDATE - SQL Server 2000 - Changes existing data in a table.

 

 

Exam Prep 70-461
Exam 70-461
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE