0% found this document useful (0 votes)
31 views25 pages

DBMS Quick Recall

Uploaded by

vkyvk222001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views25 pages

DBMS Quick Recall

Uploaded by

vkyvk222001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Page |1

AKASH KUMAR
2209005371007
Page |2

Index
S.no. Practical Name Page no.
1. Data Definition Language (DDL)
commands in RDBMS
2. Data Manipulation Language
(DML) and Data Control Language
(DCL)
3. High level language extension
with Cursor
4. High level language extension
with Trigger
5. Database design using E-R model
and Normalization
6. Design and implementation of
payroll processing system
7. Design and implementation of
Banking system
8. Design and implementation of
Library Information System
9. Design and implementation of
Student Information System

AKASH KUMAR
2209005371007
Page |3

Practical - 1
Data Definition Language (DDL) commands in RDBMS

1.Create a Table
Syntax:- Create table <table_name> (column1 Datatype (size),
column2 Datatype (size), …);
Query:- create table EMPLOYEE (emp_id integer, emp_name
varchar(50), emp_dept varchar(50));
Result:-

2.Alter a Table
Syntax:- Alter table <table_name> add column datatype;
Query:- alter table EMPLOYEE add income integer;
Result:-

AKASH KUMAR
2209005371007
Page |4

3.Truncate a Table
Syntax:- Truncate table <table_name>
Query:- truncate table EMPLOYEE;
Result:-

4.Drop a Table
Syntax:- Drop table <table_name>
Query:- drop table EMPLOYEE;

Result:-

AKASH KUMAR
2209005371007
Page |5

Practical – 2
Data Manipulation Language (DML)
1.Insert into Table
Syntax:- Insert into <table_name> (column1, column2, column3, ….)
values (value1, value2, value3 ….);
Query:- insert into EMPLOYEE (emp_id,emp_name,emp_dept,income)
values (001,'akash','sales',54000);
Result:-

2.Update a Table
Syntax:- Update <table_name> set column_name=’value1’ ,
column_name=’value2’….where <condition>;
Query:- update EMPLOYEE set emp_name='rohan', income='50000'
where emp_id=003;
Result:-

AKASH KUMAR
2209005371007
Page |6

3.Delete from a Table


Syntax:- Delete from <table_name> where <condition>;
Query:- delete from EMPLOYEE where emp_id='003';
Result:-

AKASH KUMAR
2209005371007
Page |7

Data Control Language (DCL)

1.Grant
Syntax:- Grant privilege_name on object_name to
(user_name|public|role_name);
Query:- grant select,insert,delete on *.* to 'Golu'@'localhost';
Result:-
Insert
the
values in the table after Grant

AKASH KUMAR
2209005371007
Page |8

2.Revoke
Syntax:- Revoke privilege_name on object_name from
(user_name|public|role_name);
Query:- revoke insert,delete on *.* from 'Golu'@'localhost';
Result:-

AKASH KUMAR
2209005371007
Page |9

Practical – 3
High level language extensions with cursors
EXPLICIT CURSOR

Syntax:- For creating an explicit cursor:


CURSOR <cursor_name> IS select_statement;
Declaring the cursor:
CURSOR <cursor_name> IS SELECT column1, column2,… FROM
<table_name>
Fetching the cursor:
FETCH <cursor_name> INTO variable1,variable2,..;
Closing a cursor:
CLOSE <cursor_name>
Query:-
❖ CREATE PROCEDURE cursor08()
❖ BEGIN
❖ DECLARE I INT;
❖ DECLARE J VARCHAR(50);
❖ DECLARE emp_cur CURSOR FOR SELECT emp_id, emp_name
FROM EMPLOYEE;
❖ OPEN emp_cur;
❖ FETCH emp_cur INTO I, J;
❖ SELECT I, J;
❖ CLOSE emp_cur;
❖ END;

AKASH KUMAR
2209005371007
P a g e | 10

Result:-

AKASH KUMAR
2209005371007
P a g e | 11

Practical – 4
High level language extension with Triggers
Syntax:- Creation of a trigger: CREATE TRIGGER <trigg_name>
Specified event: {BEFORE | AFTER}
Type of operation: {INSERT | UPDATE | DELETE}
ON table_name
FOR EACH ROW
BEGIN – sql statement
END;

Query:- DELIMITER //
❖ CREATE TRIGGER update_income_trigger
❖ AFTER UPDATE ON employee
❖ FOR EACH ROW
❖ BEGIN
❖ DECLARE new_income DECIMAL(10, 2);
◼ Get the new income value from the updated row
❖ SET new_income = NEW.income;
◼ Insert the updated row into the new table
❖ INSERT INTO new_employee_table (emp_id, emp_name,
emp_dept, income)
❖ VALUES (NEW.emp_id, NEW.emp_name, NEW.emp_dept,
new_income);
❖ END;//
❖ DELIMITER ;

AKASH KUMAR
2209005371007
P a g e | 12

Result:-

After using Trigger

AKASH KUMAR
2209005371007
P a g e | 13

Practical – 5
Database design using E-R model and Normalization

Syntax:- Create Table <table_name> (column1 datatype(size), column2


datatype(size), …);
Query:- CREATE DATABASE employee_db;
USE employee_db;

❖ CREATE TABLE department (


id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL );

❖ CREATE TABLE job_title (


id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL );susb bull

❖ CREATE TABLE employee (


id INT AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(255) NOT NULL,
last_name VARCHAR(255) NOT NULL,
email VARCHAR(255) UNIQUE NOT NULL,
phone_number VARCHAR(255) UNIQUE NOT NULL,
hire_date DATE NOT NULL,
job_title_id INT,
department_id INT,
FOREIGN KEY (job_title_id) REFERENCES job_title(id),
FOREIGN KEY (department_id) REFERENCES department(id));

AKASH KUMAR
2209005371007
P a g e | 14

❖ CREATE TABLE address (


id INT AUTO_INCREMENT PRIMARY KEY,
street_address VARCHAR(255) NOT NULL,
city VARCHAR(255) NOT NULL,
state VARCHAR(255) NOT NULL,
postal_code VARCHAR(255) NOT NULL,
country VARCHAR(255) NOT NULL,
employee_id INT,
FOREIGN KEY (employee_id) REFERENCES employee(id) );

❖ CREATE TABLE emergency_contact (


id INT AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(255) NOT NULL,
last_name VARCHAR(255) NOT NULL,
phone_number VARCHAR(255) NOT NULL,
relationship VARCHAR(255) NOT NULL,
employee_id INT,
FOREIGN KEY (employee_id) REFERENCES employee(id) );

❖ CREATE TABLE education (


id INT AUTO_INCREMENT PRIMARY KEY,
degree VARCHAR(255) NOT NULL,
major VARCHAR(255) NOT NULL,
institution VARCHAR(255) NOT NULL,
start_date DATE NOT NULL,
end_date DATE NOT NULL,

AKASH KUMAR
2209005371007
P a g e | 15

employee_id INT,
FOREIGN KEY (employee_id) REFERENCES employee(id) );

❖ CREATE TABLE skill (


id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
employee_id INT,
FOREIGN KEY (employee_id) REFERENCES employee(id) );

AKASH KUMAR
2209005371007
P a g e | 16

Practical – 6

Design and implementation of payroll processing system

Syntax:- Create Table <table_name> (column1 datatype(size),


column2 datatype(size),…);
Query:-
create table EMPLOYEE(
emp_id integer primary key,
emp_name varchar(50),
emp_dept varchar(50),
emp_address varchar(50),
emp_income integer);
insert into EMPLOYEE values
(001,'akash','sales','varanasi',70000),
(002,'aman','accounting','kanpur',60000),
( 003,'ankur','sales','buxar',65000),
(004,'anil','sales','chandauli',50000),
(005,'anmol','accounting','varanasi',75000),
(006,'akash','accounting','kanpur',55000);
Result:-

AKASH KUMAR
2209005371007
P a g e | 17

Fetch the Income:-

AKASH KUMAR
2209005371007
P a g e | 18

Practical – 7
Design and implementation of Banking system

Syntax:- Create Table <table_name> (column1 datatype(size), column2


datatype(size),…);
Query:-
❖ CREATE TABLE customer (
custid VARCHAR(6),
fname VARCHAR(30),
mname VARCHAR(30),
ltname VARCHAR(30),
city VARCHAR(15),
mobileno VARCHAR(10),
occupation VARCHAR(10),
dob DATE,
PRIMARY KEY (custid));

❖ CREATE TABLE branch (


bid VARCHAR(6),
bname VARCHAR(30),
bcity VARCHAR(30),
PRIMARY KEY (bid));

❖ CREATE TABLE account (


acnumber VARCHAR(6),
custid VARCHAR(6),
bid VARCHAR(6),
opening_balance INT(7),
AKASH KUMAR
2209005371007
P a g e | 19

aod DATE,
atype VARCHAR(10),
astatus VARCHAR(10),
PRIMARY KEY (acnumber),
FOREIGN KEY (custid) REFERENCES customer(custid),
FOREIGN KEY (bid) REFERENCES branch(bid));

❖ CREATE TABLE trandetails (


tnumber VARCHAR(6),
acnumber VARCHAR(6),
dot DATE,
medium_of_transaction VARCHAR(20),
transaction_type VARCHAR(20),
transaction_amount INT(7),
PRIMARY KEY (tnumber),
FOREIGN KEY (acnumber) REFERENCES account(acnumber));

❖ CREATE TABLE loan (


custid VARCHAR(6),
bid VARCHAR(6),
loan_amount INT(7),
PRIMARY KEY (custid, bid),
FOREIGN KEY (custid) REFERENCES customer(custid),
FOREIGN KEY (bid) REFERENCES branch(bid));

AKASH KUMAR
2209005371007
P a g e | 20

Result:-

AKASH KUMAR
2209005371007
P a g e | 21

Practical – 8

Design and implementation of Library Information System

Syntax:- Create Table <table_name> (column1 datatype(size), column2


datatype(size),…);

Query:-
❖ CREATE TABLE LMS_MEMBERS (
member_id INT PRIMARY KEY,
member_name VARCHAR(50),
membership_type VARCHAR(20),
contact_number VARCHAR(15));

❖ CREATE TABLE LMS_SUPPLIERS_DETAILS (


supplier_id INT PRIMARY KEY,
supplier_name VARCHAR(50),
supplier_address VARCHAR(100),
supplier_contact VARCHAR(15));

❖ CREATE TABLE LMS_FINE_DETAILS (


fine_id INT PRIMARY KEY,
member_id INT,
fine_amount DECIMAL(10, 2),
fine_date DATE,
FOREIGN KEY (member_id) REFERENCES
LMS_MEMBERS(member_id));

❖ CREATE TABLE LMS_BOOK_DETAILS (

AKASH KUMAR
2209005371007
P a g e | 22

book_id INT PRIMARY KEY,


book_title VARCHAR(100),
author_name VARCHAR(50),
publication_year INT);

❖ CREATE TABLE LMS_BOOK_ISSUE (


issue_id INT PRIMARY KEY,
member_id INT,
book_id INT,
issue_date DATE,
FOREIGN KEY (member_id) REFERENCES
LMS_MEMBERS(member_id),
FOREIGN KEY (book_id) REFERENCES LMS_BOOK_DETAILS(book_id));

Result:-

AKASH KUMAR
2209005371007
P a g e | 23

Practical – 9

Design and implementation of Student Information System

Syntax:- Create Table <table_name> (column1 datatype(size), column2


datatype(size),…);

Query:-
❖ CREATE TABLE Students (
student_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
date_of_birth DATE);

❖ CREATE TABLE Courses (


course_id INT PRIMARY KEY,
course_name VARCHAR(100),
credits INT);

❖ CREATE TABLE Enrollments (


enrollment_id INT PRIMARY KEY,
student_id INT,
course_id INT,
enrollment_date DATE,
FOREIGN KEY (student_id) REFERENCES Students(student_id),
FOREIGN KEY (course_id) REFERENCES Courses(course_id));

❖ CREATE TABLE Teachers (


teacher_id INT PRIMARY KEY,
first_name VARCHAR(50),

AKASH KUMAR
2209005371007
P a g e | 24

last_name VARCHAR(50),
department VARCHAR(50));

❖ CREATE TABLE Classes (


class_id INT PRIMARY KEY,
course_id INT,
teacher_id INT,
class_date DATE,
FOREIGN KEY (course_id) REFERENCES Courses(course_id),
FOREIGN KEY (teacher_id) REFERENCES Teachers(teacher_id));

❖ CREATE TABLE Attendance (


attendance_id INT PRIMARY KEY,
enrollment_id INT,
class_id INT,
attendance_date DATE,
FOREIGN KEY (enrollment_id) REFERENCES
Enrollments(enrollment_id),
FOREIGN KEY (class_id) REFERENCES Classes(class_id));

❖ CREATE TABLE Exams (


exam_id INT PRIMARY KEY,
course_id INT,
exam_date DATE,
max_score INT,
FOREIGN KEY (course_id) REFERENCES Courses(course_id));

❖ CREATE TABLE Scores (


score_id INT PRIMARY KEY,
enrollment_id INT,
exam_id INT,
obtained_score INT,

AKASH KUMAR
2209005371007
P a g e | 25

FOREIGN KEY (enrollment_id) REFERENCES


Enrollments(enrollment_id),
FOREIGN KEY (exam_id) REFERENCES Exams(exam_id));

Result:-

AKASH KUMAR
2209005371007

You might also like