Data that already exists in the database is not overwritten or deleted, and the data is updated to another table as a single table.
Merge into Course as Target
Using (values
(1, ' Economics ', 3),
(2, ' Literrature ', 3),
(3, ' chemistry ', 4)
)
As Source (courseid,title,credits)
On Target.courseid =source.courseid
When not matched by Target then
Insert (Title,credits)
Values (title,credits);
Merge into Student as Target
Using (values
(1, ' Tibbetts ', ' Donnie ', ' 2013-09-01 '),
(2, ' Guzman ', ' Liza ', ' 2012-01-13 '),
(3, ' Catlett ', ' Phil ', ' 2011-09-03 ')
)
As Source (studentid,lastname,firstname,enrollmentdate)
On Target.studentid=source.studentid
When not matched by Target then
Insert (Lastname,firstname,enrollmentdate)
Values (lastname,firstname,enrollmetndate);
Merge into enrollment as Target
Using (values
(1,2.00,1,1),
(2,3.50,2,2),
(3,4.00,2,3),
(4,1.80,2,1),
(5,3.20,3,1),
(6,4.00,3,2)
)
As Source (Enrollmentid,grade,courseid,studentid)
On Target.enrollmentid =source.enrollmentid
When not matched by Target then
Insert (Grade,courseid,studentid)
Values (Grade,courseid,studentid);
Initializing a database with the merge-using statement