|
| 1 | +-- Insert sample data into the Customers table |
| 2 | +MERGE INTO DimCustomer AS target |
| 3 | +USING (VALUES |
| 4 | + (1, 'John', 'Doe', '123 Main St', 'Springfield', '12345'), |
| 5 | + (2, 'Jane', 'Smith', '456 Elm St', 'Springfield', '12345'), |
| 6 | + (3, 'Bob', 'Jones', '789 Oak St', 'Springfield', '12345') |
| 7 | +) AS source (CustomerKey, FirstName, LastName, AddressLine1, City, PostalCode) |
| 8 | +ON target.CustomerKey = source.CustomerKey |
| 9 | +WHEN NOT MATCHED BY TARGET THEN |
| 10 | + INSERT (CustomerKey, FirstName, LastName, AddressLine1, City, PostalCode) |
| 11 | + VALUES (source.CustomerKey, source.FirstName, source.LastName, source.AddressLine1, source.City, source.PostalCode); |
| 12 | + |
| 13 | +-- Insert sample data into the DimProducts table |
| 14 | +MERGE INTO DimProduct AS target |
| 15 | +USING (VALUES |
| 16 | + (1, 'Bike', 'BK-001', 1000.00), |
| 17 | + (2, 'Car', 'CR-001', 2000.00), |
| 18 | + (3, 'Truck', 'TR-001', 3000.00) |
| 19 | +) AS source (ProductKey, ProductName, Category, ListPrice) |
| 20 | +ON target.ProductKey = source.ProductKey |
| 21 | +WHEN NOT MATCHED BY TARGET THEN |
| 22 | + INSERT (ProductKey, ProductName, Category, ListPrice) |
| 23 | + VALUES (source.ProductKey, source.ProductName, source.Category, source.ListPrice); |
| 24 | + |
| 25 | +-- Insert sample data into the DimDate table |
| 26 | +MERGE INTO DimDate AS target |
| 27 | +USING (VALUES |
| 28 | + (1, '2020-01-01'), |
| 29 | + (2, '2020-01-02'), |
| 30 | + (3, '2020-01-03') |
| 31 | +) AS source (DateKey, Date) |
| 32 | +ON target.DateKey = source.DateKey |
| 33 | +WHEN NOT MATCHED BY TARGET THEN |
| 34 | + INSERT (DateKey, Date) |
| 35 | + VALUES (source.DateKey, source.Date); |
| 36 | + |
| 37 | +-- Insert sample data into the FactSales table |
| 38 | +MERGE INTO FactSalesOrder AS target |
| 39 | +USING (VALUES |
| 40 | + (1, 1, 1, 1, 1, 1000.00), |
| 41 | + (2, 2, 2, 2, 2, 4000.00), |
| 42 | + (3, 3, 3, 3, 3, 9000.00) |
| 43 | +) AS source (SalesOrderKey, SalesOrderDateKey, ProductKey, CustomerKey, Quantity, SalesTotal) |
| 44 | +ON target.SalesOrderKey = source.SalesOrderKey |
| 45 | +WHEN NOT MATCHED BY TARGET THEN |
| 46 | + INSERT (SalesOrderKey, SalesOrderDateKey, ProductKey, CustomerKey, Quantity, SalesTotal) |
| 47 | + VALUES (source.SalesOrderKey, source.SalesOrderDateKey, source.ProductKey, source.CustomerKey, source.Quantity, source.SalesTotal); |
0 commit comments