1 - DML and DDL Homework
1 - DML and DDL Homework
Using the Chinook database and SQL Server Management Studio (SSMS), write SQL
queries for the following questions. Submit your answers in a single SQL file to the
online portal. Use SQL’s commenting syntax to include your name at the top of the file.
Also include the question number as a comment before each answer. The answer key to
the questions will be released after the deadline to submit homework has passed.
NOTE: The questions in this homework build off of one another so they must be executed in order.
You should add the following code to the beginning of your homework script. It will check for your
database and delete it if it exists. Replace my name with your database name:
USE master
IF DB_ID('MyDB_EricWilliamson') IS NOT NULL
BEGIN
ALTER DATABASE MyDB_EricWilliamson SET OFFLINE WITH ROLLBACK IMMEDIATE;
ALTER DATABASE MyDB_EricWilliamson SET ONLINE;
DROP DATABASE MyDB_EricWilliamson;
END
If you script everything correctly, you should be able to run your code repeatedly in one pass. It will
drop and recreate the database and its objects each time.
2. Copy all records and columns from the Chinook.dbo.Customer table into a new table in your
database called “Users”.
Include the USE keyword to select your new database.
Hint: Let SQL build the table for you using your SELECT statement.
3. Delete all records from the Users table that have an odd CustomerId number .
Hint: There is a math operator to help you with this.
11. Select all records from the Address and Users tables. (32 rows total)
Two separate queries. One for Address and one for Users
No tricks here. I want to see the content of your tables so I can grade the homework faster.