lalit last dbms
lalit last dbms
lalit last dbms
2209005371046
INDEX
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:-
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;
LALIT KUMAR
2209005371046
FOREIGN KEY (department_id) REFERENCES
department(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) );
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
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);
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);
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