Professional Documents
Culture Documents
BCS4L1-Database Management Lab
BCS4L1-Database Management Lab
CODE: BCS4L1
1
BCS4L1 DATABASE SYSTEM LABORATORY L T P C
Total Contact Hours - 30 0 0 3 2
Prerequisite –Database Management System
Lab Manual Designed by – Dept. of Computer Science and Engineering
OBJECTIVES: The main objective isstudents gain knowledge about databases for storing the data
and to share the data among different kinds of users for their business operations.
COURSE OUTCOMES (COs)
CO1 Develop database modeling for a problem.
CO2 Design a database using normalization.
CO3 Implement a data base query language.
CO4 Develop GUI using front end tool.
CO5 Develop a connection between frontend and database.
CO6 Implement a Data Manipulation Language.
MAPPING BETWEEN COURSE OUTCOMES & PROGRAM OUTCOMES
(3/2/1 INDICATES STRENGTH OF CORRELATION) 3- High, 2- Medium, 1-
Low
COs PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2 PSO3
CO1 S S 2 3
CO2 2 2 3 1 2 2 1 S 2 3
CO3 S S 2 2 2 2 3
CO4 2 2 3
CO5 S 2 2 2 2 3
CO6 2 S 1 2 2 2 2 3
Category Professional Core (PC)
Approval 37th Meeting of Academic Council, May 2015
LIST OF EXPERIMENTS
1. Data Definition, Manipulation of base tables and views
2. High level programming language extensions.
3. Front end tools.
4. Forms-Triggers-Menu Design.
5. Reports.
6. Database Design and implementation
An exercise using Open Source Software like MySQL
2
DATABASE SYSTEMS LAB - [BCS4L1] LIST OF
EXPERIMENTS
3
CONTENT
3 Exercise 8
6 Exercise 18
8 Check Constraints 38
4
EX.NO:1a
DATA DEFINITION LANGUAGES (DDL) COMMANDS Of Base Tables and Views
Aim:
DDL commands:
✴ CREATE
✴ ALTER
✴ DROP
✴ RENAME
✴ TRUNCATE
SYNTAX’S OF COMMANDS
CREATE TABLE:
To make a new database, table, index, or stored query. A create statement in SQL
creates an object inside of a relational database management system (RDBMS).
5
ALTER A TABLE:
To modify an existing database object. Alter the structure of the database.
To add a column in a table
ALTER TABLE table_name ADD column_name datatype;
To delete a column in a table
ALTER TABLE table_name DROP column column_name;
DROP TABLE:
Delete Objects from the Database
DROP TABLE table_name;
TRUNCATE TABLE:
Remove all records from a table, including all spaces allocated for the records are
removed.
EXERCISE:
Create Table
SQL> create table
employee 2 (
3 empid varchar(10) primary key,
4 empname varchar2(20) not
null, 5 gender varchar2(7) not
null,
6 age number(3) not null,
7 dept varchar2(15) not
null, 8 dob date not null,
9 doj date not null
10);
Table created.
6
SQL> create table salary
2(
3 empid varchar(10) references employee(empid),
4 salary number(10) not null,
5 dept varchar(15) not null,
6 branch varchar2(20) not
null 7 );
Table created.
DESCRIBE TABLE
SQL> desc employee;
Name Null? Type
7
SQL> desc salary;
Name Null? Type
ALTER TABLE
I. ADD:
SQL> alter table employee add(designation varchar2(15));
Table altered.
II.MODIFY
SQL> alter table employee modify (designation varchar2(20));
Table altered.
8
RENAME TABLE
SQL> create table emp
2(
3 empid varchar2(10),
4 empname varchar2(20),
5 age number(3),
6 sex char
7 );
Table created.
EMPID VARCHAR2(10)
EMPNAME VARCHAR2(20)
AGE NUMBER(3)
SEX CHAR(1)
SQL> desc
emp;
ERROR:
ORA-04043: object emp does not exist
Table altered.
9
Enter value for dept: it
Enter value for age: 22
Enter value for sex: m
old 1: insert into emp values(&no,'&name','&dept',&age,'&sex')
new 1: insert into emp values(1,'arun','it',22,'m')
1 row created.
1 arun it 22 m
10
2 bala service 26 m
3 chitra sales 25 f
SQL> commit;
Commit complete.
Commit complete.
DROP TABLE
RESULT:
11
EX.NO:1b
DATA MANIPULATION LANGUAGE (DML) OF BASE TABLES AND VIEWS
Data manipulation language allows the users to query and manipulate data in existing
schema in object. It allows following data to insert, delete, update and recovery data in
schema object.
Aim:
To study DML commands in RDBMS.
DML COMMANDS:
❖ INSERT
❖ UPDATE
❖ DELETE
❖ SELECT
QUERY:
Query is a statement in the DML that request the retrieval of data from database.
❖ The portion of the DML used in a Query is called Query language. The
SELECT statement is used to query a database
SYNTAX OF COMMANDS
INSERT:
Values can be inserted into table using insert commands. There are two types of insert
commands. They are multiple value insert commands (using ‘&’ symbol) single value insert
command (without using ‘&’symbol)
Syntax:
INSERT INTO table_name VALUES (value1, value2, value3,…..);
(OR)
INSERT INTO table_name (column1, column2, column3,….) VALUES
(value1,value2,value3,…..);
12
UPDATE:
This allows the user to update the particular column value using the where clause
condition.
Syntax:
UPDATE <table_name> SET <col1=value> WHERE <column=value>;
DELETE:
This allows you to delete the particular column values using where clause condition.
Syntax:
DELETE FROM <table_name> WHERE <condition>;
SELECT:
The select statement is used to query a database .This statement is used to retrieve the
information from the database. The SELECT statement can be used in many ways. They are:
1. Selecting some columns :
To select specified number of columns from the table the
Syntax:
To select all columns from the table * is used instead of column names.
Syntax:
The DISTINCT keyword is used to return only different values (i.e. ) this
command does not select the duplicate values from the table.
Syntax:
13
4. Select using IN:
If you want to get the rows which contain certain values, the best way to do it
is to use the IN conditional expression.
Syntax:
BETWEEN can be used to get those items that fall within a range.
Syntax:
6. Renaming:
The select statement can be used to rename either a column or the entire
table.
Syntax:
Renaming a column:
Renaming a table:
7. Sorting
:
The select statement with the order by Clause is used to sort the contents
Syntax:
14
8. To select by matching some patterns:
The select statement along with like clause I is used to match strings. The like
condition is used to specify a search pattern in a column.
Syntax:
SELECT column name FROM table_name WHERE Column name LIKE “% or-“;
The SELECT INTO statement is most often used to create backup copies of
tables or for archiving records.
Syntax:
WHERE condition.
We can use the SELECT statement to select the ‘null’ values also.
For retrieving roes where some of the columns have been defined as NULLs there is a special
comparison operator of the form IS [NOT]NULL.
Syntax:
Syntax:
15
EXERCISE:
INSERT COMMAND
16
old 1: insert into employee
values('&empid','&empname','&gender',&age,'&dept','&dob','&doj','&desi
new 1: insert into employee values('it9001','arunkumar','male',22,'it','12-jan-1988','23-oct-
2006'
1 row created.
17
Enter value for doj: 01-jan-1995
Enter value for desig: manager
old 1: insert into employee
values('&empid','&empname','&gender',&age,'&dept','&dob','&doj','&desi
1 row created.
18
Enter value for dept: service
Enter value for dob: 31-mar-
1877 Enter value for doj: 3-jun-
1999 Enter value for desig:
manager old 1: insert into
employee
values('&empid','&empname','&gender',&age,'&dept','&dob','&doj','&desi
new 1: insert into employee values('ser9001','jagadheesh','male',33,'service','31-
mar- 1877','3-jun
1 row created.
20
SQL> insert into salary values(‘&empid’,&salary,’&dept’,’&branch’);
Enter value for empid: it9002
Enter value for salary: 18000
Enter value for dept: it
Enter value for branch: abt maruthi
old 1: insert into salary values('&empid',&salary,'&dept','&branch')
new 1: insert into salary values('it9002',18000,'it','abt maruthi')
1 row created.
21
Enter value for dept: service
Enter value for branch: chennai cars
old 1: insert into salary values('&empid',&salary,'&dept','&branch')
new 1: insert into salary values('ser9001',35000,'service','chennai cars')
1 row created.
22
new 1: insert into salary values('sal9006',17000,'sales ','abt maruthi')
1 row created.
8 rows selected.
DOJ DESIGNATION
23
DOJ DESIGNATION
DOJ DESIGNATION
24
it9001 35000 it abt maruthi
it9002 18000 it abt maruthi
acc9001 35000 accounts cars india
acc9002 26000 accounts cars india
ser9001 35000 service chennai cars
ser9006 12000 service greenland cars
sal9001 40000 sales abt maruthi
sal9006 17000 sales abt maruthi
8 rows selected.
25
1 row created.
UPDATE COMMAND
SQL> update employee set empname = 'arunprasanth' where empid='it9001';
1 row updated.
arunprasanth manager
balakrishnan coordinator
kannan manager
magudeshwaran asst
26
manager jagadheesh manager
27
muruganandam supervisor
suresh manager
sharmila executive
8 rows selected.
SELECT COMMAND
To retrieve particular column
SQL> select empname from emp;
EMPNAME
arun
bala
bakyara
j chitra
1 arun it 22 m
2 bala accounts 26 m
3 bakyaraj stores 30 m
4 chitra sales 24 f
DELETE COMMAND
To delete particular record
SQL> delete emp where empid=1;
1 row deleted.
28
SQL> select * from emp;
EMPID EMPNAME DEPT AGE S
2 bala accounts 26 m
3 bakyaraj stores 30 m
4 chitra sales 24 f
Table created.
IDNO NUMBER
NAME VARCHAR2(10)
BRANCH VARCHAR2(4)
Table altered.
IDNO NUMBER
29
NAME VARCHAR2 (10)
IDNO NUMBER
1 row created.
1 row created.
30
Enter value for idno: 04
degree: 'BE'
1 row created.
SQL> /
1 row created.
1 ASHOK CSE BE
2 BHAVANA CSE BE
3 CAVIN CSE BE
4 DANNY IT BE
5 HARRY IT BE
31
2 rows updated.
32
SQL> select * from student;
1 ASHOK CSE BE
2 BHAVANA CSE BE
3 CAVIN CSE BE
4 DANNY IT B.TECH
5 HARRY IT B.TECH
1 row deleted.
NOT NULL
SQL> select * from student;
1 ASHOK CSE BE
2 BHAVANA CSE BE
3 CAVIN CSE BE
4 DANNY IT B.TEC
H
varchar(10),branch varchar(6)
); Table created.
33
SQL> desc staff;
NAME VARCHAR2(10)
BRANCH VARCHAR2(6)
1 row
created.
SQL> /
1 row created.
SQL> /
34
Enter value for branch: 'IT'
35
old 1: insert into staff values(&idno,&name,&branch)
* ERROR at line 1:
UNIQUE
name varchar(10),
salary number
);
Table created.
ROLLNO NUMBER
NAME VARCHAR2(10)
SALARY NUMBER
37
new 1: insert into employee values(1,'anton',10290)
1 row created.
SQL> /
1 row
created.
SQL> /
ERROR at line 1:
PRIMARY KEY
name varchar(10),
cost number(6)
);
Table created.
38
SQL> desc cars;
NAME VARCHAR2(10)
COST NUMBER(6)
model: 1098
1 row
created.
SQL> /
SQL> /
40
insert into cars values(1098,'innova',600000)
ERROR at line 1:
CHECK CONSTRAINT:
rno number(5),
name varchar(10),
);
Table created.
RNO NUMBER(5)
NAME VARCHAR2(10)
SALARY NUMBER(10)
41
SQL> /
'rohit'
1 row
created.
SQL> /
'dhoni'
ERROR at line 1:
FOREIGN KEY
name varchar(10),
permit number(6)
42
);
Table created.
43
SQL> desc admin;
NAME VARCHAR2(10)
PERMIT NUMBER(6)
1 row
created.
SQL> /
1 row created.
SQL> /
44
old 1: insert into admin values(&stuid,'&name',&permit)
45
new 1: insert into admin values(4,'SANJAY',45)
1 row created.
SQL> /
1 row created.
1 ASWIN 80
2 ROHIT 67
4 SANJAY 45
5 KAMALINI 35
branch varchar(6),
sec varchar(2)
);
Table created.
46
SQL> insert into course values(&stuid,'&branch','&sec');
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
CSE
47
Enter value for sec: A
ERROR at line 1:
1 row deleted.
ERROR at line 1:
1 ASWIN 80
2 ROHIT 67
4 SANJAY 45
SQL> select * from course;
STUID BRANCH
SE
1 CSE A
2 CSE A
4 IT A
48
SQL> create table student
idno varchar(4),
name varchar(10),
dept varchar(4),
degree varchar(6),
year number(4)
);
table created.
IDNO VARCHAR2(4)
NAME VARCHAR2(10)
DEPT VARCHAR2(4)
DEGREE VARCHAR2(6)
YEAR NUMBER(4)
49
new 1: insert into student values('a01','aaron','cse','BE',2)
1 row created.
SQL> /
1 row created.
SQL> /
IT
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
51
SQL> SELECT * FROM STUDENT;
6 rows selected.
DISTINCT
CSE
ECE
IT
MECH
AARON
AKIL
BENNY
COOK
DANNY
ELAN
6 rows selected.
52
IN
SQL> select * from student where name BETWEEN 'AARON' and 'COOK';
AS
A0
1
A0
2
A0
3
B01
B02
B03
6 rows selected.
SORT
53
SQL> select * from student where year<3 order by name desc;
IDNO NAME DEPT DEGREE YEAR
54
B03 ELAN IT B.TECH 1
B02 DANNY MECH BE 1
B01 COOK CSE BE 1
A03 BENNY IT B.TECH 2
A02 AKIL ECE BE 2
A01 AARON CSE BE 2
6 rows selected.
LIKE
55
IS NULL
no rows selected
LOGICAL OR
RESULT:
Thus the data manipulation language (dml) of base tables and views are executed.
56
57