DBMS Project Report
DBMS Project Report
of
Database Management System
DEPARTMENT OF
COMPUTER SCIENCE AND ENGINEERING
GALAXY GLOBAL GROUP OF INSTITUTIONS, AMBALA
INDEX
8. Write SQL queries for extracting data from more than one
table.
Why SQL?
Nowadays, SQL is widely used in data science and analytics. Following are the reasons which
explain why it is widely used:
History of SQL
1970 − Dr. Edgar F. "Ted" Codd of IBM is known as the father of relational databases.
He described a relational model for databases.
1974 − Structured Query Language (SQL) appeared.
1978 − IBM worked to develop Codd's ideas and released a product named System/R.
1986 − IBM developed the first prototype of relational database and standardized by
ANSI. The first relational database was released by Relational Software which later
came to be known as Oracle.
1987 − SQL became the part of the International Organization for Standardization
(ISO).
Working of SQL:
When you are executing an SQL command for any RDBMS, the system determines the best
way to carry out your request and SQL engine figures out how to interpret the task.
There are various components included in this process. These components are −
Query Dispatcher
Optimization Engines
Classic Query Engine
SQL Query Engine, etc.
A classic query engine handles all the non-SQL queries, but a SQL query engine won't handle
logical files. Following is a simple diagram showing the SQL Architecture −
Practical-2
AIM - Write the Data Types in SQL?
Each column in a database table is required to have a name and a data type.
An SQL developer must decide what type of data that will be stored inside each column when
creating a table. The data type is a guideline for SQL to understand what type of data is
expected inside of each column, and it also identifies how SQL will interact with the stored
data.
For every database, data types are primarily classified into three categories.
Numeric Datatypes
Date and Time Database
String Database
There are nine subtypes which are given below in the table. The table contains the range of
data in a particular type.
Data Type From To
-263 (- 263 -1
bigint
9,223,372,036,854,775,808) (9,223,372,036,854,775,807)
bit 0 1
THEORY:
SQL – SQL is Structured Query Language which is computer language for
storing, Manipulating and retrieving data stored in a relational database. SQL
is the standard language for Relational Database System. SQL is categorized
into five different languages:
▪ DDL – Data Definition Language
▪ DML – Data Manipulation Language
▪ DCL – Data Control Language
▪ DQL – Data Query Language
▪ TCL – Transaction Control Language
DDL (Data Definition Language) - is to Create, Alter, Drop, Delete, Truncate
and Rename the table.
DML (Data Manipulation Language) – is to Insert, Select, Delete, Update.
DQL (Data Query Language) is also known as DRL (Data Retrieval Language) - select
SOURCE CODE:
Commands for DDL:
(ii) Specify both the column names and the values to be inserted::
Syntax: Insert into table_name(column1, column2, column3,--)values(value1,
value2, value3,--);
Query: insert into student_info (Roll_No,Name,City) values (2321025,'Aanchal','Ambala');
Output:
Output:
Practical-4
AIM: Commands of DDL (Update, Delete, Rename, Truncate ).
THEORY:
(a) Update Command:
Syntax: update table_name SET column1 = value1, where condition;
Query: update student_info SET S_Name = 'Vanshika' where Roll_No='2321024';
Output:
(b)Delete Command:
Syntax: Delete from table_name where condition;
Query: delete from student_info where Roll_No = '2321025';
Output:
student_information; Output:
Practical-5
AIM: Write the queries for DML (Data Manipulation Language) in RDBMS.
(a) Create Command Using Primary key:
Syntax: Create table table_name (column_name datatype(size),
column2_name datatype(size) Primary Key);
Query: create table Employee(Id int(10) PRIMARY KEY, Name
char(20),Salary int(20));
2) %alphabet
Syntax: select* from tableName where attributeName like “%alphabet”;
Query: select* from S_Name where Address like ”%t”;
3) %alphabet
Syntax: select* from tableName where attributeName like “%alphabet ”;
Query: select* from S_Name where Name like “%i ”;
(c) DEFAULT Command:
1. Adding default in new column:
Syntax: Alter table tableName ADD(clm_name datatype(size) DEFAULT “value”;
Query: alter table S_Name ADD(College char(20) DEFAULT “ACE”);
Average Command:
Syntax: Select avg (column_name) from table_name;
Query: select avg (E_Salary) from Employee;
Sum Command:
Syntax: Select sum (column_name) from table_name;
Query: select sum(E_Salary) from Employee;
Distinct Command:
Syntax: Select distinct column_name from table_name;
Query: select distinct E_Salary,E_D_id from Employee;
Relational Operators:
AND Command:
Syntax: Select * from table_name where column_name AND column_name;
Query: Select * from Employee where E_D_id = 1 AND E_Name = ‘Shawn’;
OR Command:
Syntax: Select * from table_name where column_name OR column_name;
Query: Select * from Employee where E_D_id = 2 AND E_Name = ‘Shawn’;
NOT Command:
Syntax: Select * from table_name where NOT column_name;
Query: Select * from Employee where not E_Name = ‘John’;
Practical-8
AIM- Write SQL queries for extracting data from more than one table.
Theory- SQL Join statement is used to combine data or rows from two or more tables based on
a common field between them. Different types of Joins are as follows:
• INNER JOIN
• LEFT JOIN
• RIGHT JOIN
• FULL JOIN;
Inner Join- The INNER JOIN keyword selects all rows from both the tables as long as the
condition is satisfied. This keyword will create the result-set by combining all rows from both
the tables where the condition satisfies i.e value of the common field will be the same.
Syntax- SELECT table1.column1, table1.column2, table2.column1, ....
FROM table1 INNER JOIN table2 ON
table1.matching_column = table2.matching_column;
Query: select * from
studentdata;
Select* from
stucoursedata;
Select stucoursedata.Course , studentdata.Name, studentdata.Gender from
studentdata INNER JOIN stucoursedata ON
studentdata.RollNo=stucoursedata.RollNo;
Left Join-This join returns all the rows of the table on the left side of the join and
matches rows for the table on the right side of the join. For the rows for which
there is no matching row on the right side, the result-set will contain null. LEFT
JOIN is also known as LEFT OUTER JOIN.
Syntax- SELECT table1.column1, table1.column2, table2.column1, ....
FROM table1 LEFT JOIN table2 ON table1.matching_column = table2.matching_column;
Query: select studentdata.Name, studentdata.RollNo, stucoursedata.Course from studentdata
LEFT JOIN stucoursedata on studentdata.RollNo= stucoursedata.RollNo;
Right Join- RIGHT JOIN is similar to LEFT JOIN. This join returns all the rows of the
table on the right side of the join and matching rows for the table on the left side of the join.
For the rows for which there is no matching row on the left side, the result-set will contain
null. RIGHT JOIN is also known as RIGHT OUTER JOIN.
Syntax- SELECT table1.column1, table1.column2, table2.column1, ....
FROM table1 RIGHT JOIN table2 ON table1.matching_column
= table2.matching_column;
Query: select studentdata.Name, studentdata.RollNo, stucoursedata.Course
from stucoursedata
RIGHT JOIN studentdata on studentdata.RollNo= stucoursedata.RollNo;
Cross join- We use the cross join to combine two different tables, then we will get the
Cartesian product of the sets of rows from the joined table. When each row of the first table
is combined with each row from the second table, it is known as Cartesian join or cross join.
Syntax-
SELECT TableName1.columnName1, TableName2.columnName2 FROM TableName1
CROSS JOIN TableName2 ON TableName1.ColumnName = TableName2.ColumnName;
Query- select * from studentdata CROSS JOIN stucoursedata ON studentdata.RollNo=
stucoursedata.RollNo;
Practical-9
AIM- Concepts for ROLL BACK, COMMIT & CHECK POINTS.
COMMIT;
Query:
COMMIT;
Rollback command:
This command restores the database to last committed state. It is also use with
savepoint command to jump to a savepoint in a transaction.
Syntax:
ROLLBACK;
Query:
ROLLBACK;
Savepoint command:
Savepoint command is used to temporarily save a transaction so that you can
rollback to that point whenever necessary.
Syntax: SAVEPOINT name;
Query: SAVEPOINT P;
It is used with rollback.
Syntax: ROLLBACK to
name; Query: ROLLBACK to
P;
Practical-10
AIM- Write SQL queries for the following:
1. Write a query on the customer table whose output will exclude all
customers with a rating greater than equal to 100 unless they are
located in Shimla.
5. Write a query to display the details of all Employees in the descending order of DOJ.
6. Write a query to add a new row with the following: 19, ‘Harish Roy’ , ‘HEAD-IT’,
‘S02’, ’09-SEP-2007’ , ’21-APR-1983’.
7. Write a query to display NAME and DESIG of those Employees whose
SALGRADE is either (SGRADE) S02 or S03.
8. Write a query to display the content of all the EMPLOYEE table, whose DOJ is in between
‘09-Feb-2006’ and ‘08-Feb-2009’.
Practical-11
Select monthname(‘date’);
Select day(‘date’);
Select dayname(‘date’);
Select year(‘date’);
Practical-12
Aim – Create a View to display Employee’s Name and their Projects.
The employees table is created as follows-