0% found this document useful (0 votes)
3 views

Notes Dbms

Uploaded by

poondimalar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Notes Dbms

Uploaded by

poondimalar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 37

VISION OF SCHOOL OF ENGINEERING

“Develop and create women technocrats who can meet the challenges of the corporate
world and emerge as leaders contributing ton industry and society.”

MISSION OF SCHOOL OF ENGINEERING

 To produce global women technologists by imparting quality education through


pursuit of excellence that stimulates the intellect and the heart.
 Inculcate in all staff and students scientific temper and research attitude.

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

VISION OF THE DEPARTMENT

To empower women technocrats in the field of computer engineering and prepare the
students for higher studies and professional career through technology, innovations
and human values to serve the changing needs of our nation.

MISSION OF THE DEPARTMENT

 To promote the all-round development of the students by providing them sound


technical knowledge in the field of computer science and engineering based on
the current advances in technology to help the development of nation.
 To develop employability skills and research capability in women graduates
through quality technical education.
 To provide learning for the enhancement of technical skills, problem solving
ability, team spirit, entrepreneurial skills with emphasis on value education with
social ethics and cultural values in women technocrats

PROGRAM OUTCOMES (PO):


Engineering Graduates will be able to:

1. Engineering knowledge: Apply the knowledge of mathematics, science,


engineering fundamentals and an engineering specialization to the solution of
complex engineering problems.

2. Problem analysis: Identify, formulate, review research literature, and analyze


complex engineering problems reaching substantiated conclusions using first
principles of mathematics, natural sciences, and engineering sciences.

3. Design/development of solutions: Design solutions for complex engineering


problems and design system components or processes that meet the specified needs
with appropriate consideration for the public health and safety, and the cultural,
societal, and environmental considerations.

4. Conduct investigations of complex problems: Use research-based knowledge


and research methods including design of experiments, analysis and interpretation
of data, and synthesis of the information to provide valid conclusions.

5. Modern tool usage: Create, select, and apply appropriate techniques, resources,
and modern engineering and IT tools including prediction and modeling to
complex engineering activities with an understanding of the limitations.

6. The engineer and society: Apply reasoning informed by the contextual


knowledge to assess societal, health, safety, legal and cultural issues and the
consequent responsibilities relevant to the professional engineering practice.

7. Environment and sustainability: Understand the impact of the professional


engineering solutions in societal and environmental contexts, and demonstrate the
knowledge of, and need for sustainable development.

8. Ethics: Apply ethical principles and commit to professional ethics and


responsibilities and norms of the engineering practice.

9. Individual and team work: Function effectively as an individual, and as a


member or leader in diverse teams, and in multidisciplinary settings.

10. Communication: Communicate effectively on complex engineering activities


with the engineering community and with society at large, such as, being able to
comprehend and write effective reports and design documentation, make effective
presentations, and give and receive clear instructions.
11. Project management and finance: Demonstrate knowledge and
understanding of the engineering and management principles and apply these to
one‘s own work, as a member and leader in a team, to manage projects and in
multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and
ability to engage in independent and life-long learning in the broadest context of
technological change.
PROGRAM EDUCATIONAL OBJECTIVES (PEOs) for B.E. (AI & DS)

The graduates in AI & DS will be able to

PEO1 Demonstrate the technical skills to analyse and design suitable solutions for
problems using standard practices, tools and techniques.

PEO2 Carry out higher education and research in Artificial Intelligence and Data
Science areas to address the basic needs of the society.

PEO3 Explore technological developments and will be ethically and socially


responsible solution providers and entrepreneurs.

PROGRAM SPECIFIC OUTCOMES (PSO) for B.E (AI & DS)

The graduates in AI & DS will be able to

PSO1 Apply the concepts learnt through courses like Data Structures, Data Mining,
Cloud Computing, Machine Learning, Data Science, Computer Vision, Data
Visualization and programming languages to solve real life problems.

PSO2 Acquaint with the contemporary trends in industries and thereby innovate novel
solutions to existing problems.
INDEX
Sl.No. DATE NAME OF THE EXPERIMENT PAGE MARKS SIGNATURE
No.
1. Data Definition Language (DDL)
commands -Data Manipulation
Language (DML) and Data Control
Language (DCL).
2. Programs using Data definition –Table
creation and Constraints.

3. Programs using Insert, select, update


and delete commands.

4. Programs using Nested queries and join


queries.

5. Apply multiple sub-queries and


Correlated sub-queries.

6. Programs using Object and set


operators in relational database.

7. Programs using Control structures.

8. Programs to create database triggers.

9. Creation of Views-Synonyms-Sequence-
Indexes-save point.

10. Creating a database using various


constraints.

11. Design a database and implement with


a front end tool.

12. Mini Project - Create an Student


Management Application Using Mysql.

EXPERIMENT BEYOND SYLLABUS

13. Mini Project


EX.NO : 1 STUDY OF DDL, DML AND DCL COMMANDS
DATE :
_______________________________________________________________

AIM:
To study and implement the Data Definition Language, Data
Manipulation Language and Data Control Language commands using MySQL
Workbench.

DESCRIPTION:
DATABASE:
A database is a collection of information that is organized so that it can be
easily accessed, managed and updated.
DATABASE MANAGEMENT SYSTEM:
A Database management system (DBMS) is a set of programs that
manages any number of databases.
DDL (DATA DEFINITION LANGUAGE):
DDL or Data Definition Language actually consists of the SQL commands that
can be used to define the database schema. It simply deals with the descriptions
of the database schema and is used to create and modify the structure of data
base objects in the database.
DDL commands:
 CREATE
 DROP
 ALTER
 TRUNCATE
 RENAME
CREATE Command:
CREATE is used to create the database or its objects (like table,
index, functions, views, store procedure and triggers).
SYNTAX:
CREATE TABLE table_name
(
Column_1 datatype,
Column_2 datatype,
Column_3 datatype,
……………………
);

CREATE COMMAND:
Output:

ALTER Command:
This command is used to alter the structure of the database.
SYNTAX:
ALTER TABLE table_name ADD Column_name datatype;
ALTER COMMAND:
Output:

RENAME Command:
This command is used to rename an object existing in the database.
SYNTAX:
ALTER TABLE old_table_name RENAME TO new_table_name;
RENAME COMMAD:
Output:
DML (DATA MANIPULATION LANGUAGE):
Data Manipulation Language (DML) allows us to modify the
database instance by inserting, modifying, and deleting its data. It is
responsible for performing all types of data modification in a database.
DML Commands are:
 INSERT
 UPDATE
 DELETE
 SELECT
INSERT Command:
This is a statement in a SQL query. This command is used to insert
data into the rows of a table.
SYNTAX:
INSERT INTO table_name VALUE (value1, value2, value3, ...…. ,valueN);
INSERT COMMAND:
UPDATE Command:
This command is used to update or modify the value of a column in the table.
SYNTAX:
UPDATE table_name SET [Column_name1=Value1, ……… ,
Column_nameN = ValueN WHERE Condition];
UPDATE COMMAND:
output

DELETE Command:
This command is used to remove one or more rows from a table.
SYNTAX:
DELETE FROM table_name WHERE Condition;
DELETE COMMAND:

Output:
TRUNCATE Command:
This command is used to remove all rows from the table, but the structure of
the table still exits.
SYNTAX:
TRUNCATE TABLE table_name;
TRUNCATE COMMAND:
Output:

DROP Command:
This command is used to remove an existing table along with its
structure from the database.
SYNTAX:
DROP TABLE table_name;
DROP COMMAND:
Output:

Preparedness 5

Performance 5

Result 5

Record 5
Inference:
Total 20
Hence,I have learned the data
definition languages , data manipulation languages and data control languages.

EX.NO : 2 PROGRAMS USING DATA DEFINITION –


TABLE CREATION AND CONSTRAINTS
DATE :

AIM:
To implement programs using the data definition language, table
creation and constraints.
DESCRIPTION:
DATABASE:
A database is a collection of information that is organized so that it can be
easily accessed, created and updated.
DATABASE MANAGEMENT SYSTEM:
A database managemet system (DBMS) is a set of programs that manages any
number of databases.
SQL CONSTRAINTS
To maintain accuracy and integrity of the data inside.
 NOT NULL.
 UNIQUE.
 PRIMARY KEY.
 FOREIGN KEY.
 CHECK.

NOT NULL
The not null constraints enforces a column to not accept the null values.
SYNTAX
CREATE TABLE table_name(column_name1 datatype NOT
NULL,column name2 datatype[size]);
QUERY:

Create table student


(
ID int not null,
Name varchar(100) not null,
Age int
);

Output:
UNIQUE
Unique constraint uniquely identifies each record in a database table.
SYNTAX
CREATE TABLE table_name(column name datatype UNIQUE);
QUERY:
Create table student1
(
ID int not null unique,
Name varchar(100) not null,
Age int
);
Output:
PRIMARY KEY
The primary key constraint uniquely identifies each record in database
table.Primary key cannot contain null values.
SYNTAX
CREATE TABLE table_name(column_name1 datatype PRIMARY
KEY);
QUERY:
Create table student1
(
ID int not null,
Name varchar(100) not null,
Age int,
Primary key(ID)
);

Output:

FOREIGN KEY
It is used to relate two tables.
SYNTAX
[CONSTRAINT constraint_name] FOREIGN KEY (column_name)
REFERENCES referenced_table_name (column_name);
QUERY:
Create table branch
(
branch_id int primary key,
Branch_name varchar(100) not null,
Location varchar(100)
);
Create table employee
(
emp_id int primary key,
ename varchar(100) not null,
Job varchar(100),
Salary int,
branch_id int,
FOREIGN KEY(branch_id) references branch(branch_id)
);

Output:
CHECK
Check constraint is used to check the value of a column between a
range.
SYNTAX
[CONSTRAINT constraint_name] CHECK (condition);
QUERY:
Create table student3
(
ID int not null,
Name varchar(100) not null,
Age int,
CHECK(Age>=18)
);

Output:

DEFAULT CONSTRAINT:
Used to set default values

SYNTAX
Column_name DEFAULT ‘value’
QUERY:
Create table student4
(
ID int not null,
Name varchar(100) not null,
Age int,
City varchar(100) DEFAULT ‘Chennai’
);
Output:

Preparedness 5

Performance 5

Result 5

Record 5

Total 20

Inference:
Hence I have learned to implement the data definition-table creation and
SQL constraints using SQL

EX.NO : 3 PROGRAMS USING INSERT, SELECT, UPDATE


AND DELETE COMMANDS
DATE :
_______________________________________________________________
AIM:
To implement a program using insert, select, update and delete .
DESCRIPTION:
DML (DATA MANIPULATION LANGUAGE)
CREATE:
It is used to create table.
SYNTAX:
create table table_name
(
Column1,
Column2,
.
.
Columnn
);

INSERT
It is used to insert data into a table.
SYNTAX
INSERT into table_namevalues(data1,data2,……);
QUERY:
Insert into students
values(“Anupama”,”CSE”,101,18)
UPDATE
It is used to update the existing data data in a table.
SYNTAX
UPDATE table_name set column_name=value WHERE condition;
QUERY:
UPDATE students set age=19 WHERE rollno=101;
Output:

DELETE
It is used to delete all the records from a table.
SYNTAX
DELETE from table_name;
QUERY:
DELETE from students where rollno=109;
SELECT
The select statement is used to select data from a database.
SYNTAX
SELECT * from TABLE table_name;
QUERY:
SELECT * from students;

Preparedness 5

Performance 5

Result 5

Record 5

Total 20

Inference:
Hence I have learned to implement the data manipulation languages insert,
select, update and delete using SQL.
EX. NO:4 PROGRAMS USING NESTED QUERIES AND JOIN
QUERIES

DATE:
_______________________________________________________________
AIM:
To write a program using nested queries and join queries.
DESCRIPTION:
NESTED QUERIES
 A Sub query or Inner query or a Nested query is a query within another
SQL query and embedded within the WHERE clause.
 A sub query is used to return data that will be used in the main query as
a condition to further restrict the data to be retrieved.
 Sub queries can be used with the SELECT, INSERT, UPDATE, and
DELETE statements along with the operators like =, <, >, >=, <=, IN,
BETWEEN, etc.
A few rules that sub queries must follow −
 Sub queries must be enclosed within parentheses.
 A sub query can have only one column in the SELECT clause, unless
multiple columns are in the main query for the sub query to compare its
selected columns.
 An ORDER BY command cannot be used in a sub query, although the
main query can use an ORDER BY. The GROUP BY command can be
used to perform the same function as the ORDER BY in a sub query.
 Sub queries that return more than one row can only be used with
multiple value operators such as the IN operator.
 The BETWEEN operator cannot be used with a sub query. However, the
BETWEEN operator can be used within the sub query.
SUB QUERIES WITH THE SELECT STATEMENT
Sub queries are most frequently used with the SELECT statement.
syntax :
SELECT column_name [, column_name ]
FROM table1 [, table2 ]
WHERE column_name OPERATOR
(SELECT column_name [, column_name ]
FROM table1 [, table2 ]
[WHERE])
Query:
Select ID,dept_Name,Age from dept
Where ID in(select ID from employees where FirstName=’Banu’);
Output:
SUB QUERIES WITH THE INSERT STATEMENT
Sub queries also can be used with INSERT statements. The INSERT
statement uses the data returned from the sub query to insert into another table.
The selected data in the sub query can be modified with any of the character,
date or number functions.
syntax:
INSERT INTO table_name[ (column1 [, column2 ]) ]
SELECT [ *|column1 [, column2 ]
FROM table1 [, table2 ]
[ WHERE VALUE OPERATOR ]
Query:
insert into Employee values(35,"Rathi","Rani",(select Dept_Code from
Department where Dept_Code = 214),70000);
select * from Employee;Output:

SUBQUERIES WITH THE UPDATE STATEMENT


The sub query can be used in conjunction with the UPDATE statement.
Either single or multiple columns in a table can be updated when using a sub
query with the UPDATE statement.
syntax :
UPDATE table
SET column_name = new_value
[ WHERE OPERATOR [ VALUE ]
(SELECT COLUMN_NAME
FROM TABLE_NAME)
[ WHERE) ]

Query:

update Employee set Salary=60000

where Employee_Id=(select Employee_Id where Firstname='Wei');


select * from Employee;

Output:

SUBQUERIES WITH THE DELETE STATEMENT


The sub query can be used in conjunction with the DELETE statement
like with any other statements mentioned above.
syntax :
DELETE FROM TABLE_NAME
[ WHERE OPERATOR [ VALUE ]
(SELECT COLUMN_NAME
FROM TABLE_NAME)
[ WHERE) ]
Query:
delete from Department where Dept_Code in
(select Dept_Code from Employee where Firstname='Rathi');
select * from Department;

Output:
JOIN QUERIES
The SQL Joins clause is used to combine records from two or more
tables in a database. A JOIN is a means for combining fields from two tables
by using values common to each.
There are different types of joins available in SQL
 INNER JOIN − returns rows when there is a match in both tables.
 LEFT JOIN − returns all rows from the left table, even if there are no
matches in the right table.
 RIGHT JOIN − returns all rows from the right table, even if there are no
matches in the left table.
 FULL JOIN − returns rows when there is a match in one of the tables.
 SELF JOIN − is used to join a table to itself as if the table were two
tables, temporarily renaming at least one table in the SQL statement.
 CARTESIAN JOIN − returns the Cartesian product of the sets of
records from the two or more joined tables.
SQL - INNER JOINS
The most important and frequently used of the joins is the INNER JOIN.
They are also referred to as an EQUIJOIN.
The INNER JOIN creates a new INFERENCE table by combining column
values of two tables (table1 and table2) based upon the join-predicate. The
query compares each row of table1 with each row of table2 to find all pairs of
rows which satisfy the join-predicate. When the join-predicate is satisfied,
column values for each matched pair of rows of A and B are combined into
aINFERENCE row.
syntax :
SELECT table1.column1, table2.column2...
FROM table1
INNER JOIN table2
ON table1.common_field = table2.common_field;
Query:
Select e.emp_id,e.ename,e.Job,b.branchName
From employee As e
Inner join branch As b
On e.branch_id=b.branch_id
Order by e.emp_id
Output:
CREATING A TABLE:

CREATING ANOTHER TABLE:

INNER JOIN

SQL - LEFT JOINS


The SQL LEFT JOIN returns all rows from the left table, even if there
are no matches in the right table. This means that if the ON clause matches 0
(zero) records in the right table; the join will still return a row in the
INFERENCE, but with NULL in each column from the right table.
This means that a left join returns all the values from the left table, plus
matched values from the right table or NULL in case of no matching join
predicate.
syntax :
SELECT table1.column1, table2.column2...
FROM table1
LEFT JOIN table2
ON table1.common_field = table2.common_field;
Query:
Select e.emp_id,e.ename,e.Job,b.branchName
From employee As e
left join branch As b
On e.branch_id=b.branch_id
Order by e.emp_id

Output:LEFT JOIN:

SQL - RIGHT JOINS


SQL RIGHT JOIN returns all rows from the right table, even if there are
no matches in the left table. This means that if the ON clause matches 0 (zero)
records in the left table; the join will still return a row in the INFERENCE, but
with NULL in each column from the left table.
This means that a right join returns all the values from the right table, plus
matched values from the left table or NULL in case of no matching join
predicate.
The basic syntax of a RIGHT JOIN is as follow:
SELECT table1.column1, table2.column2...
FROM table1
RIGHT JOIN table2
ON table1.common_field = table2.common_field;
QUERY:
Select e.emp_id,e.ename,e.Job,b.branchName
From employee As e
right join branch As b
On e.branch_id=b.branch_id
Order by e.emp_id

OUTPUT:RIGHT JOIN:
SQL - FULL JOINS
The SQL FULL JOIN combines the INFERENCEs of both left and right
outer joins.
The joined table will contain all records from both the tables and fill in NULLs
for missing matches on either side.
syntax :
SELECT table1.column1, table2.column2...
FROM table1
FULL JOIN table2
ON table1.common_field = table2.common_field;
Query:
select
e.Dept_Code,e.Employee_Id,e.Firstname,e.Lastname,e.Salary,d.Dept_Name
From Employee as e
Full outer join Department as d
on e.Dept_Code=d.Dept_Code
order by e.Employee_Id
OUTPUT:
SQL - SELF JOINS

The SQL SELF JOIN is used to join a table to itself as if the table were
two tables; temporarily renaming at least one table in the SQL statement.

syntax :

SELECT a.column_name, b.column_name...


FROM table1 a, table1 b
WHERE a.common_field = b.common_field;
Query:
select
e.Dept_Code,e.Employee_Id,e.Firstname,e.Lastname,e.Salary,d.Dept_Name
from Employee as e,Department as d
where e.Dept_Code=d.Dept_Code

Output:

SQL - CARTESIAN or CROSS JOINS

The CARTESIAN JOIN or CROSS JOIN returns the Cartesian product


of the sets of records from two or more joined tables. Thus, it equates to an
inner join where the join-condition always evaluates to either True or where the
join-condition is absent from the statement.

syntax:

SELECT table1.column1, table2.column2...


FROM table1, table2 [, table3 ]
Query:
select
e.Dept_Code,e.Employee_Id,e.Firstname,e.Lastname,e.Salary,d.Dept_Name
from Employee as e cross join Department as d;

OUTPUT:
Preparedness 5

Performance 5

Result 5

Record 5

Total 20

INFERENCE:

Hence,I have learned the program using nested queries and join
queries

EX. NO:5 APPLY MULTIPLE SUB-QUERIES AND


CORRELATED SUB-QUERIES
DATE:
_______________________________________________________________

AIM:

To implement a program by applying sub-queries and correlated sub –


queries.

DESCRIPTION:

Correlated subqueries are used for row-by-row processing. Each


subquery is executed once for every row of the outer query. A correlated
subquery is evaluated once for each row processed by the parent statement. The
parent statement can be a SELECT, UPDATE, or DELETE statement.

SELECT column1, column2, ....


FROM table1 outer
WHERE column1 operator
(SELECT column1, column2
FROM table2
WHERE expr1 = outer.expr2);
A correlated subquery is one way of reading every row in a table and
comparing values in each row against related data. It is used whenever a
subquery must return a different INFERENCE or set of INFERENCEs for each
candidate row considered by the main query. In other words, you can use a
correlated subquery to answer a multipart question whose answer depends on
the value in each row processed by the parent statement.

CREATION OF TABLE 1 AND INSERTION: students

CREATION OF TABLE 2 AND INSERTION: grade


SUB QUERIES WITH THE SELECT STATEMENT

Sub queries are most frequently used with the SELECT statement.

syntax :
SELECT column_name [, column_name ]
FROM table1 [, table2 ]
WHERE column_name OPERATOR
(SELECT column_name [, column_name ]
FROM table1 [, table2 ]
[WHERE])

Query:

select Name from students


where Id in ( select Id from grade where marks >(select avg(marks) from
grade));

Output:

INSERT STATEMENT

Sub queries also can be used with INSERT statements. The INSERT
statement uses the data returned from the sub query to insert into another table.
The selected data in the sub query can be modified with any of the character,
date or number functions.

syntax :
INSERT INTO table_name[ (column1 [, column2 ]) ]
SELECT [ *|column1 [, column2 ]
FROM table1 [, table2 ]
[ WHERE VALUE OPERATOR ]

Query:

insert into grade(Id,Course, grades, marks) select Id, 'new subject', 'A', 90 from
grade
where marks >(select avg(marks)from grade);
select * from grade

Output:

UPDATE STATEMENT

The sub query can be used in conjunction with the UPDATE statement.
Either single or multiple columns in a table can be updated when using a sub
query with the UPDATE statement.

syntax :
UPDATE table
SET column_name = new_value
[ WHERE OPERATOR [ VALUE ]
(SELECT COLUMN_NAME
FROM TABLE_NAME)
[ WHERE) ]

Query:

update grade set marks = marks + 1 where Id in (select Id from students


where Dept in (select Dept from students group by Dept having
avg(marks)>85));
select * from grade;

Output:
Preparedness 5

Performance 5

Result 5
Record 5

Total 20

INFERENCE:

Hence,I have learned the multiple sub-query and correlated


sub-query and executed successfully.

You might also like