Sie sind auf Seite 1von 8

MUHAMMAD FAHAD

CMS: 356324
Submitted to: Waqas Ahmed
04-11-2020

DATABASE SYSTEMS

LAB-3
TASK-1: Create DEPARTMENT table with the
following structure and set the DEPTNO as primary
key and DNAME is unique key.

STEPS
1) First, we create the database and the table named “DEPARTMENT”.
2) Then create a Primary Key named “DEPTNO” of integer type.
3) Now create a Unique Key named “DNAME” of varchar(10).
4) Create column “LOCATION” of varchar(10).
5) Create column “ESTABLISHED” of DATE type.
6) Insert values in the table as shown
TASK-2: Write a query to add constraints to the
EMPLOYEE table that EMPNO as the primary key
and DEPTNO as the foreign key.

STEPS
1) First, we create another table named “EMPLOYEE” in the same
database
2) Then create a PRIMARY KEY named “EMPNO” of int type.
3) Create a column named “DEPTNO” referencing to “DEPTNO” of
Department as FOREIGN KEY.
TASK-3: WRITE the query, to create table, which have at least
16 columns and each column has CHECK constraint then insert
the data and observe the results.

Code

STEPS
1) First create a database
2) Then we add 16 columns each having a “CHECK”
3) We take PRIMARY KEY as “CMS ID”

OUTPUT
STEPS
1) Insert the values in the respected column as shown in the Screenshot.

TASK-4: WRITE the query, to create table which have 16


columns and table have at least two PRIMARY KEY then observe
the results.
CODE

STEPS
1) First create a database
2) Then we add 16 columns each having a “CHECK”
3) We take “CMS ID” and “USERNAME” as PRIMARY KEY
4) As we can see TWO Primary key is not possible.
Task-5: WRITE the query, to create table which have 16 columns and
each column has to be UNIQUE KEY then insert the data and observe
the results. Also, apply check constraint to one column i-e one column
needs to check and accept only more than 3000 number of the entry
Code

STEPS
1) First create a database
2) Then we add 16 columns each having a “CHECK”
3) Set all the columns as Unique Key.
4) Apply check constraint on “CMS ID” which only accepts numbers
greater than 3000.

OUTPUT

Task-6: Create Four(4) tables


Code

STEPS
1) First create a database
2) Create a Table named “EMPLOYEE”
3) Add all the given columns with their data types
4) Create another table named “Potential”
5) Add all the given columns with their data types
6) Create a column named “employee_id” referencing to “employee_id” of
EMPLOYEE as FOREIGN KEY.
7) Create another table named “DEPARTMENT”
8) Add all the given columns with their data types
9) Create a column named “employee_id” referencing to “employee_id” of
EMPLOYEE as FOREIGN KEY.
Create a column named “potential_id” referencing to “potential_id” of
POTENTIAL as FOREIGN KEY.
10) Create another table named “DEPARTMENT”
11) Add all the given columns with their data

ENTITY RELATION DIAGRAM

Das könnte Ihnen auch gefallen