In this workshop you'll learn how to:
- Create a database;
- Drop a database;
- Create tables;
- Alter tables;
- Drop tables;
- SQL Server 2017+ Installed;
- SQL Server Management Studio Installed;
- Since we'll be creating our own databases, there is no database required for this workshop.
Recreate the following database called Game_db
based on the following schema:
- Create a database named
Game_db
, then refresh your object explorer in SQL Management Studio so that the database is visible. Then execute the statementUSE Game_db
to make the database active as the default database. - Create the
Game
table. - Create the
Goalcard
table. - Create the
Hallcard
table. - Create the
Player
table- The
Id
column is automagically determined by the database engine - Make sure to add a
constraint
calledCH_Player_Colors
so that thePlayer
can only choose ared
orblack
color.
- The
- Create the
Game_Hallcard
table. - Create the
Player_Goalcard
table. - Add an extra column
Email
to thePlayer
entitytype, which is aVARCHAR
of max. 50 characters long. - Adjust the column
Email
from thePlayer
entity type to a maximum length of 100 characters. - Add an extra column
Phonenumber
to thePlayer
entity type, which entitytype would be a good fit? - Remove the column
Phonenumber
fron thePlayer
entity type since we don't need it anymore.
Given the following Relational Model:
- Employee(Id, Name, Email)
- Project(Name, Description, StartDate, EndDate)
- Allocation(EmployeeId, ProjectName, HoursWorked)
- IR: EmployeeId References Employee(Id), mandatory
- IR: ProjectName References Project(Name), mandatory
Complete the following tasks:
- Create the table
Employee
- IR:
Id
is created by the database engine. - IR:
Name
is required, - IR:
Email
is unique and required,
- IR:
- Create the table
Project
- Create the table
Allocation
- The default for
HoursWorked
is 3. - If a
Project
is deleted, so should theallocation(s)
. - If an
Employee
is deleted, so should theallocation(s)
.
- The default for
- In the
Project
table, add a constraint so that eachBeginDate
must be before theEndDate
, name the contraintCH_Project_Begin_Before_End
- Adjust the
Project
table, so that theName
cannot be longer than 50 characters long. - Write an ALTER statement removing the constraint which ensures that
Email
s must be unique in theEmployee
table.
- Why is it sometimes better to embrace certain table/column/... names like
Name
,Type
,Order
, etc. with square brackets like the following[Name], [Type], [Order]
?
A possible solution for these exercises can be found here.