lalit last dbms

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 25

LALIT KUMAR

2209005371046
INDEX

S.no. Practical Name Page no.

1. Data Defini on Language (DDL)


commands in RDBMS
2. Data Manipula on Language
(DML) and Data Control Language
(DCL)
3. High level language extensions with
cursors
4. High level language extension with
Triggers
5. Database design using E-R model and
Normaliza on
6. Design and implementa on of payroll
processing system
7. Design and implementa on of Banking
system
8. Design and implementa on of Library
Informa on System
9. Design and implementa on of Student
Informa on System

Practical - 1
Data Defini on Language (DDL) commands in RDBMS
1.Create a Table
Syntax:- Create table <table_name> (column1 Datatype (size),
column2 Datatype (size), …);
Query:- create table CUSTOMER (C_id integer, C_name varch
ar(40), C_branch varchar(40));
Result:-

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

LALIT KUMAR
2209005371046
3.Truncate a Table
Syntax:- Truncate table <table_name>
Query:- alter table CUSTOMER;
Result:-

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

LALIT KUMAR
2209005371046
Practical – 2
Data Manipula on Language (DML)
1.Insert into Table
Syntax:- Insert into <table_name> (column1, column2,
column3, ….) values (value1, value2, value3 ….);
Query:- insert into CUSTOMER (C_id,C_name,C_branch)
values (004,'yakshit','telenor');
Result:-

2.Update a Table
Syntax:- Update <table_name> set column_name=’value1’ ,
column_name=’value2’….where <condi on>;
Query:- update CUSTOMER set C_name='yakshit',
C_branch='bsnl' where C_id=004;
Result:-

LALIT KUMAR
2209005371046
3.Delete from a Table
Syntax:- Delete from <table_name> where <condi on>;
Query:- delete from CUSTOMER where C_id='004'; Result:-

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
'ABC'@'localhost';

LALIT KUMAR
2209005371046
Result:-
Insert the values in the table a er Grant

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

LALIT KUMAR
2209005371046
Practical – 3
High level language extensions with cursors
EXPLICIT CURSORS
Syntax:- For crea ng 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;

LALIT KUMAR
2209005371046
Result:-

Practical – 4

LALIT KUMAR
2209005371046
High level language extension with Triggers
Syntax:- Crea on of a trigger: CREATE TRIGGER
<trigg_name>
Specified event: {BEFORE | AFTER}
Type of opera on: {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_CUSTOMER_table (C_id, C_name,
C_branch);
 VALUES (NEW.C_id, NEW.C_name, NEW.C_branch);
 END;//
 DELIMITER ;

LALIT KUMAR
2209005371046
Result:-

A er using Trigger

LALIT KUMAR
2209005371046
Practical – 5
Database design using E-R model and Normaliza on
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_ tle (id INT


AUTO_INCREMENT PRIMARY KEY,
tle 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_ tle_id INT, department_id
INT,
FOREIGN KEY (job_ tle_id) REFERENCES job_ tle(id),

LALIT KUMAR
2209005371046
FOREIGN KEY (department_id) REFERENCES
department(id));

 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, rela
onship VARCHAR(255) NOT NULL,
employee_id INT,
FOREIGN KEY (employee_id) REFERENCES
employee(id) );

 CREATE TABLE educa on ( id


INT AUTO_INCREMENT PRIMARY
KEY, degree VARCHAR(255) NOT
NULL,
major VARCHAR(255) NOT
NULL, ins tu on VARCHAR(255)
NOT NULL, start_date DATE NOT
NULL, end_date DATE NOT
NULL, 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,
LALIT KUMAR
2209005371046
FOREIGN KEY (employee_id) REFERENCES
employee(id) );
Prac cal – 6
Design and implementa on of payroll processing
system

Syntax:- Create Table <table_name> (column1


datatype(size), column2 datatype(size),…);
Query:-
create table CUSTOMER(
C_id integer primary key,
C_name varchar(50), C_branch
varchar(50),
varchar(50), );
insert into CUSTOMER values
(001,’lalit’,’jio’)
(002,’atul’,’airtel’)
(003,’shivam’,’vi’)
Fetch the branch:-

LALIT KUMAR
2209005371046
Practical – 7
Design and implementa on of Banking system
Syntax:- Create Table <table_name> (column1
datatype(size), column2 datatype(size),…);
Query:-
 CREATE TABLE
customer ( cus d
VARCHAR(6), fname
VARCHAR(30), mname
VARCHAR(30), ltname
VARCHAR(30), city
VARCHAR(15),
mobileno VARCHAR(10),
occupa on VARCHAR(10),
dob DATE,
PRIMARY KEY (cus d));

 CREATE TABLE
branch ( bid
VARCHAR(6), bname
VARCHAR(30), bcity
VARCHAR(30),
PRIMARY KEY (bid));
 CREATE TABLE
account ( acnumber
VARCHAR(6), cus d
VARCHAR(6), bid
VARCHAR(6),
opening_balance INT(7),
aod DATE, atype
VARCHAR(10), astatus
VARCHAR(10),
PRIMARY KEY (acnumber),
FOREIGN KEY (cus d) REFERENCES customer(cus d),
FOREIGN KEY (bid) REFERENCES branch(bid));

 CREATE TABLE
trandetails ( tnumber
VARCHAR(6), acnumber
VARCHAR(6),
dot DATE,
medium_of_transac on
VARCHAR(20), transac on_type
VARCHAR(20), transac on_amount
INT(7),
PRIMARY KEY (tnumber),
FOREIGN KEY (acnumber) REFERENCES
account(acnumber));

LALIT KUMAR
2209005371046
 CREATE TABLE loan
( cus d VARCHAR(6),
bid VARCHAR(6),
loan_amount INT(7),
PRIMARY KEY (cus d, bid),
FOREIGN KEY (cus d) REFERENCES customer(cus d),
FOREIGN KEY (bid) REFERENCES branch(bid));
Result:-

Practical – 8

LALIT KUMAR
2209005371046
Design and implementa on of Library Informa on
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));
LALIT KUMAR
2209005371046
 CREATE TABLE LMS_BOOK_DETAILS
( book_id INT PRIMARY KEY, book_ tle
VARCHAR(100), author_name
VARCHAR(50),
publica on_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:-

Practical -9
Design and implementa on of Student Informa on system

LALIT KUMAR
2209005371046
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),
last_name VARCHAR(50),
LALIT KUMAR
2209005371046
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 A endance (


a endance_id INT PRIMARY KEY,
enrollment_id INT,
class_id INT,
a endance_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,

LALIT KUMAR
2209005371046
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,
FOREIGN KEY (enrollment_id) REFERENCES
Enrollments(enrollment_id),
FOREIGN KEY (exam_id) REFERENCES Exams(exam_id));

Result:-

LALIT KUMAR
2209005371046

You might also like