Lab No. 04
Lab No. 04
Lab No. 04
04 DATE: 12/09/2023
HOW TO CREATE PRIMARY and FOREIGN KEYS IN MS SQL
SERVER
Lab outcomes:
After completing this lab, students will be able to:
Know about Microsoft SQL server
Know about SQL server management studio
Create table in SQL server
Create primary and foreign keys
SOFTWARE REQUIRED:
Microsoft SQL server
SQL server management studio
Theory:
Primary Key:
A Primary key is a unique column we set in a table to easily identify and locate data in
queries. A table can have only one primary key. The primary key column has a unique value
and doesn’t store repeating values. A Primary key can never take NULL values.
For example, in the case of a student when identification needs to be done in the class, the
roll number of the student plays the role of Primary key. Similarly, when we talk about
employees in a company, the employee ID is functioning as the Primary key for
identification.
Let us now understand the Syntax of creating the table with the Primary key specified.
Syntax:
Task 1:
1) Create a Primary Key and Foreign Key for two tables i.e. Student’s Table and
Subject’s Table also add the procedure (query) and output screenshots with the
lab task.
Solution:
Student Table Query:
Rubrics:
Report not Plagiarized Requirements Observations Appropriate Correctly
submitted content are listed and are recorded computation drawn
presented or experimental along with s or conclusion
Laboratory incomplete procedure is detailed numerical with
Reports submission or presented procedure analysis is exact results
late performed and complete
report in all
respects
Category Ungraded Very Poor Poor Fair Good Excellent
Marks 0 1 2 3 4 5
Marks 0 1 2 3 4 5