Unit 3 updated2
Unit 3 updated2
one record/
tuple
3.1. Overview of Relational Database
Management System
• Each field in a table has to be given a name
and data type.
• Data type is the type of data value you want
to store in the field.
• best describes the fields in the table
3.1. Overview of Relational Database
Management System
Set Doctor ID as
primary key
Patient ID char(5) CREATE TABLE Patient(
Name char(20) Pt_ID CHAR(20) PRIMARY KEY,
Sex char(1) Name CHAR(20),
Sex CHAR(1),
Age Integer
Age INT,
Address char(15)
Address CHAR(15),
App Date datetime APP_Date DATETIME,
SET Patient ID as primary
Doc_ID char(5) REFERENCES
key & Doctor ID as a
foreign key
Doctor(Dr_ID))
Here is the r/ship
Create the Department & Employee Table
using the following info. Use SQL command
Employee ID CHAR(10)
Depart ID char(10)
Emp Name CHAR(20)
Dept Name char(30)
Position CHAR(20)
Dept Location char(20) Salary CURRENCY
Block Number Integer
• SET Employee ID as
* SET Depart ID as primary key &
primary key Depart ID Foreign key
CREATE TABLE Department(
Dept_ID CHAR(10) PRIMARY KEY,
Dept_Name CHAR (30),
Dept_Location CHAR(20),
Bl_No INT)
Employee ID CHAR(10) CREATE TABLE Employee(
Emp Name CHAR(20) Emp_ID CHAR(10) PRIMARY KEY,
Position CHAR(20) Name CHAR(20),
Salary CURRENCY Position CHAR(20),
Salary CURRENCY,
SET Employee ID as Depart_ID char(10) REFERENCES
primary key & Department(Dept_ID))
Depart ID Foreign key
Q1. Create the following tables using
SQL commands Access:
• Teacher table with attribute – teacher id
(CHAR(10)), name (CHAR(20)),
sex(CHAR(1)), age(INTEGER),
specialization (CHAR(15)). Set the
Teacher id as primary key.
CREATE TABLE Teacher(trid char(10)
PRIMARY KEY, name char(20), sex
char(1), Age INT, Specialization char(15))
Q1. Create the following tables using
SQL commands Access:
Student table with attribute – student id
(CHAR(10)), name (CHAR(20)),
sex(CHAR(1)), age(INTEGER), grade level
(INTEGER). Set the Student id as primary
key.
CREATE TABLE Student(StudentID
char(10) PRIMARY KEY, NAME
CHAR(20), SEX CHAR(1), Age INT,
Gradelevel INT)
Q1. Create the following tables using SQL
commands Access:
• Grade table with attribute – student id
(CHAR(10)), teacher id(CHAR(10), course
code(CHAR(20)), mark(INTEGER). Use st_id as a
FOREIGN KEY to create a relationship with the
Student table.
create table grade(Stu_Id Char(10)
REFERENCES Student(st_Id),
teach_ID char(10) REFERENCES
Teacher(tr_Id), C_Code char(20),
mark INT)
Q. The following CREATE statement has a
problem (i.e. has syntax error). Trace the
problem and rewrite the statement to fix
the error
CREATE TABLE Patient (pid INTEGER, P_Name TEXT
P_Age INT
Page 80
Solution
INSERT INTO Grade (student_Id,
Teacher_ID, Subject, Mark)
VALUES( “1001/2013”, “1001/2010”,
“Physics”,80)
Activity 3.9
Activity 3.9