CSE 304 - Database Systems Lab Manual
CSE 304 - Database Systems Lab Manual
CSE 304
Department offering the LAB course
Computer Science and Engineering
Course Pre-requisites
CSE 103, CSE 201
Course Description
This course will familiar the students with the concepts of Database Management Systems and they
will learn how to use this concept in application level. At the end of the class, we expect the students
to be able to design database structure and implement the structure in computer program.
Exp
NAME OF EXPERIMENT Date Sign Remark
No
2 Database Connectivity
Implement Data Definition Language (Create, Alter, Drop,
3 Truncate, and Rename)
6 Views
7 Procedure
8 Cursor
9 Trigger
10 Concepts of Normalization
CONTENTS
2 Database Connectivity 11
3 Implement Data Definition Language (Create, Alter, Drop, Truncate, and Rename) 20
6 Views 32
7 Procedure 35
8 Cursor 38
9 Trigger 40
10 Concepts of Normalization 42
TUPLE
A single entry in a table is called a Tuple or Record or Row. A tuple in a table represents a set of
related data. For example, the above Employee table has 4 tuples/records/rows.
Following is an example of single record or tuple.
1 Adam 34 13000
ATTRIBUTE
A table consists of several records (row), each record can be broken down into several smaller parts
of data known as Attributes. The above Employee table consists of four
attributes, ID, Name, Age and Salary.
ATTRIBUTE DOMAIN
When an attribute is defined in a relation (table), it is defined to hold only a certain type of values,
which is known as Attribute Domain. Hence, the attribute Name will hold the name of employee
for every tuple. If we save employee's address there, it will be violation of the Relational database
model.
Name
Adam
ADVANTAGES OF RDBMS
Alex
It is easy to use.
Stuart - 9/401, OC Street, Amsterdam
It is secured in nature.
The data manipulation can be done.
It limits redundancy and replication of the data.
Database Systems Lab (CSE 304) Page 8 of 52
It offers better data integrity.
It provides better physical data independence.
It offers logical database independence i.e. data can be viewed in different ways by the
different users.
It provides better backup and recovery procedures.
It provides multiple interfaces.
Multiple users can access the database which is not possible in DBMS.
DISADVANTAGES OF RDBMS
Software is expensive.
Complex software refers to expensive hardware and hence increases overall cost to avail the
RDBMS service.
It requires skilled human resources to implement.
Certain applications are slow in processing.
It is difficult to recover the lost data.
MySQL DATABASE
MySQL, is one of the most popular Open Source SQL database management systems. MySQL is a
fast, easy-to-use RDBMS being used for many small and big businesses. MySQL is developed,
marketed, and supported by MySQL AB, which is a Swedish company.
MySQL is becoming so popular because of many good reasons:
MySQL is released under an open-source license. So you have nothing to pay to use it.
MySQL is a very powerful program in its own right. It handles a large subset of the
functionality of the most expensive and powerful database packages.
MySQL uses a standard form of the well-known SQL data language.
MySQL works on many operating systems and with many languages including PHP
MySQL works very quickly and works well even with large data sets.
MySQL is very friendly to PHP, the most appreciated language for web development.
MySQL supports large databases, up to 50 million rows or more in a table.
MySQL is customizable
CONCLUSION: Thus we, have studied DBMS, and RDBMS with its advantages, disadvantages
and mysql database successfully.
Viva Voce Question
1. Define Database? What are DBMS and RDBMS?
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
OBJECTIVES
To understand DDL commands.
THEORY
DATABASE QUERIES:
Before creating any tables, MySQL requires you to create a database by executing the
CREATE DATABASE command.
Create a database
CREATE DATABASE <database name>
Delete a database
DROP DATABASE <database name>
Select the database
USE <database name>
List all databases
SHOW databases;
Rename a database
ALTER DATABASE <database name> RENAME <new database name>
TABLE QUERIES:
To Create a table
Database Systems Lab (CSE 304) Page 21 of 52
CREATE TABLE <tablename> (<fieldname>< fieldtype>(<fieldsize>) , …)
List all tables in the current database
SHOW tables;
Show table format with column names and data types
DESCRIBE <table name>
Modify the structure of table
ALTER TABLE <table name> <alter specifications>
ALTER TABLE <table name> DROP COLUMN <column name>
ALTER TABLE<table name> ADD COLUMN <column name> datatype>(<size>)
Delete the table
DROP TABLE <table name>
CONSTRAINTS:
Primary key A PRIMARY KEY constraint for a table enforces the table to accept unique
data for a specific column and this constraint create a unique index for accessing the table
faster
UNIQUE The UNIQUE constraint in Mysql does not allow to insert a duplicate value in a
column.
NOT NULL In Mysql NOT NULL constraint allows to specify that a column can not
contain any NULL value.
FOREIGN KEY A FOREIGN KEY in mysql creates a link between two tables by one
specific column of both table. The specified column in one table must be a
PRIMARY KEY and referred by the column of another table known as FOREIGN KEY.
CHECK The CHECK constraint determines whether the value is valid or not from a
logical expression.
DEFAULT While inserting data into a table, if no value is supplied to a column, then the
column gets the value set as DEFAULT
PROCEDURE
i. CREATE DATABASE command
ii. USE DATABASE command
iii. CREATE TABLE command
iv. PRIMARY KEY,NOT NULL etc
v. SHOW TABLES command
vi. DESCRIBE TABLE command
vii. ALTER TABLE command
viii. ALTER TABLE command
ix. DROP TABLE command
x. DROP DATABASE command
RESULT:
The DDL commands have been executed successfully.
OUTPUT
PROBLEMS
Database Systems Lab (CSE 304) Page 22 of 52
1. Consider the database for a college and design an ER diagram. Write the query for the
following.
i. Create the tables:
Student (sid, sname, sex, dob,dno)
Department (dno, dname)
Faculty (F_id, fname, designation, salary,dno)
Course (cid, cname, credits,dno)
Register (sid,cid,sem )
Teaching (f_id,cid,sem)
Hostel(hid,hname,seats,)
ii. Include the necessary constraints NOT NULL, DEFAULT, CHECK, and PRIMARY
KEY, UNIQUE.
iii. Create a database college
iv. Use college as the current database
v. Display all the tables in college database
vi. Describe the structure of all tables
vii. Modify the student table to add a new field ‘grade’
2. Consider the database for a banking enterprise. Write the queries for the below
questions.
i. Create the following tables