DBMS File
DBMS File
DBMS File
Practical-1
Data Definition Language(DDL) commands in RDBMS
CREATE-
Syntax-
create table table_name
(
column_1 datatype,
column_2 datatype,
column_3 datatype,
);
Query-
CREATE TABLE students
(
name char(10), rollno int(2), branch char(10),
);
Output-
ALTER-
Syntax- Alter table table_name
Add column_name datatype;
Query-
mysql> alter table students add primary key(rollno);
Query OK, 0 rows affected (0.07 sec)
Records: 0 Duplicates: 0 Warnings: 0
2
Output-
TRUNCATE-
Syntax- Truncate Table table_name;
Query- mysql> truncate table students;
Query OK, 0 rows affected (0.03 sec)
Output-
DROP-
Syntax- Drop Table table_name;
Query- mysql> drop database student;
Query OK, 1 row affected (0.04 sec)
Output-
3
Practical-2
Data Manipulation Language(DML) and Data Control
Language(DCL)
INSERT-
Syntax-
Insert into <table name> (column list) values (column values);
Query-
mysql> insert into students values('Anuj',14,'CSE'),
-> ('Ankit',13,'CSE');
Query OK, 2 rows affected (0.01 sec)
Output-
UPDATE-
Syntax-
Update <table_name> Set column_number=value_number
where condition;
Query-
mysql> update students set name='Rohan' where rollno=14;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
4
Output-
Delete-
Syntax- Delete from <table_name> where condition;
Query-
mysql> delete from students where name='Rohan';
Query OK, 1 row affected (0.01 sec)
Output-
Query-
CREATE USER Abhishek IDENTIFIED BY 'password';
grant select, insert, delete on CA to Abhishek;
Output-
AFTER GRANT
Revoke-
Syntax- Revoke privilege_name on object_name
To {user_name | public | role_name}
Query-
revoke insert, select, update on CA to Abhishek;
Output-
6
Practical-3
High level language extensions with cursors
CURSOR-
Syntax-
CURSOR cursor_name is select_statement;
DECLARE-
CURSOR cur_students is
SELECT name, rollno from students;
FETCH-
FETCH cur_students into ST_name,ST_rollno;
CLOSE-
CLOSE cur_students;
Query-
mysql> delimiter //
mysql> create procedure cursor12()
-> begin
-> declare j int;
-> declare n char(10);
-> declare cur cursor for SELECT STUDENT_NAME,
STUDENT_ROLLNO from students;
-> OPEN cur;
-> FETCH cur into j,n;
-> SELECT j,n;
7
Output-
8
Practical-4
High level language extensions with Triggers
Syntax-
Create (or replace) Trigger trigger_name
{Before | After}
{Insert [or] | Update [or] | Delete}
ON table_name
[FOR EACH ROW]
DECLARE
Declaration-statements
BEGIN
Executable-statements
END;
Query-
mysql> create table account(acct_num int, amount Decimal(10,2));
Query OK, 0 rows affected (0.05 sec)
mysql> create trigger ins_sum Before insert on account
-> For Each Row Set @sum = @sum + New.amount;
Query OK, 0 rows affected (0.01 sec)
mysql> delimiter //
mysql> Set @sum = 0;
-> insert into account values(137,14.98),(141,1937.50),(97,-100.00);
-> select @sum as 'Total amount inserted';
-> //
Query OK, 0 rows affected (0.00 sec)
9
Output-
10
Practical-6
Database design using E-R model and Normalization
Syntax-
Create table <table_name> (Column_name1 Datatype (Size),
Column_name2 Datatype (Size)……..);
Query-
1) mysql> create table Zone(
-> ZONE_ID int PRIMARY KEY,
-> ZONE_NAME char(20));
Output-
13
Practical-7
Design and implementation of payroll processing
system
Syntax-
Create table <table_name> (Column_name1 Datatype (Size),
Column_name2 Datatype (Size)……..);
Query-
1) mysql> Create Table STAFF(
-> Staff_ID integer PRIMARY KEY,
-> Staff_NAME TEXT NOT NULL,
-> Staff_ADD TEXT NOT NULL,
-> Staff_MOB TEXT NOT NULL,
-> DEPT_NO TEXT NOT NULL,
-> DEPT_NAME TEXT NOT NULL,
-> SALARY TEXT NOT NULL
-> );
Query OK, 0 rows affected (0.04 sec)
2)
mysql> insert into Staff values(101,'Abhishek','New Delhi','9592330812','2095',
-> 'Finance','20000');
mysql> insert into Staff values(102,'Ankur','New Delhi','9596881232','2136',
-> 'Finance','26000');
mysql> insert into Staff values(103,'Vishal','New Delhi','9598527705','3036',
-> 'Finance','30000');
14
Output-
15
Practical-8
Design and implement of Banking system
Syntax-
Create table<table_name> (column_name1 Datatype (Size),
Column_name2 datatype (Size)……);
Query-
1) mysql> CREATE TABLE branch(
-> branch_id INT NOT NULL AUTO_INCREMENT,
-> branch_name VARCHAR(30) NOT NULL,
-> assets INT NOT NULL,
-> branch_address VARCHAR(255) NOT NULL,
-> PRIMARY KEY(branch_id)
-> );
-> );
-> );
-> );
Output-
19
Practical-9
Design and implement of Library Information System
Syntax-
Create table<table_name> (column_name1 Datatype (Size),
Column_name2 datatype (Size)……);
Query-
1) mysql> Create table LMS_MEMBERS
-> (
-> MEMBER_ID Varchar(10),
-> MEMBER_NAME Varchar(30) NOT NULL,
-> CITY Varchar(20),
-> DATE_REGISTER Date NOT NULL,
-> DATE_EXPIRE Date ,
-> MEMBERSHIP_STATUS Varchar(15)NOT NULL,
-> Constraint LMS_cts1 PRIMARY KEY(MEMBER_ID)
-> );
-> );
-> );
22
Output-
23
Practical-11
Automatic Backup of Files and Recovery of Files
BACKUP-
Syntax-
C:\Windows\System32>cd/
C:\>cd program files
C:\Program Files>cd mysql
C:\Program Files\MySQL>dir
Volume in drive C is Windows
Volume Serial Number is 2A99-05BD
Directory of C:\Program Files\MySQL
27-01-2023 13:36 <DIR> .
27-01-2023 13:34 <DIR> ..
27-01-2023 13:34 <DIR> MySQL Server 5.7
27-01-2023 13:36 <DIR> MySQL Shell 8.0
27-01-2023 13:34 <DIR> MySQL Workbench 8.0
0 File(s) 0 bytes
5 Dir(s) 112,946,413,568 bytes free
C:\Program Files\MySQL>cd mysql*
C:\Program Files\MySQL\MySQL Server 5.7>cd bin
C:\Program Files\MySQL\MySQL Server 5.7\bin>mysqldump -u root -p account
> newaccount.sql
Enter password: ********
Query-
24
RECOVERY-
Syntax-
C:\Program Files\MySQL\MySQL Server 5.7\bin>mysql -u root -p account <
newaccount.sql
Enter password: ********
C:\Program Files\MySQL\MySQL Server 5.7\bin>
Query-
mysql> create database account;
Query OK, 1 row affected (0.00 sec)
OUTPUT-
Before Recovery
25
After Recovery