/* Update--1 using an update with the associated subquery . Create a test table
Create TABLE Table1 ( a varchar (ten), B varchar (ten), C varchar (ten), CONSTRAINT [pk_ Table1] PRIMARY KEY CLUSTERED ( a ASC ) ) on [PRIMARY]
create TABLE table2 ( a varchar (ten), C varchar (ten), CONSTRAINT [pk_table2] PRIMARY KEY Clustered ( a ASC < Span class= "Apple-converted-space" > ) ) on [ Primary] go
< Span class= "Apple-converted-space" >< Span class= "Apple-converted-space" >< Span class= "Apple-converted-space" >--2. Creating test Data
< Span class= "Apple-converted-space" >< Span class= "Apple-converted-space" >< Span class= "Apple-converted-space" >insert into Table1 values (' Zhao ', ' ASDs ', null)
< Span class= "Apple-converted-space" >< Span class= "Apple-converted-space" >< Span class= "Apple-converted-space" > Insert into Table1 values (' money ', ' ASDs ', ' + ')
< Span class= "Apple-converted-space" >< Span class= "Apple-converted-space" >< Span class= "Apple-converted-space" >< Span class= "Apple-converted-space" >insert into Table1 values (' Sun ', ' ASDs ', ' ')
Insert into Table1 values (' Lee ', ' ASDs ', null)
Insert into Table2 values (' Zhao ', ' all ')
Insert into Table2 values (' money ', ' + ')
Insert into Table2 values (' sun ', ' + ')
Insert into Table2 values (' Li ', ' up ')
GO SELECT * from Table1
--3. Updating with update mode
Update Table1 Set c = (select C from Table2 where a = table1.a) where c is null GO
--4. Displaying the updated results
SELECT * FROM Table1
GO
--5. Deleting a test table
Drop TABLE Table1
Drop TABLE Table2
MSSQL SQL Efficient Correlated subquery Update batch Update