SQL
SQL
A PROJECT REPORT
ON
Project Guide
Mr. Hemendra
2
DECLARATION
I hereby declare that the following documented project file on “Information System
Management” is an original and authentic work done by me for the partial fulfilment of
Bachelor of Business Administration (General) degree program.
I hereby declare that all the endeavour put in the fulfilment of the task is genuine and original
to the best of my knowledge & I have not submitted it earlier elsewhere.
Signature
Sarthak
BBA(G)
(5th Semester)
3
ACKNOWLEDGEMENT
It is in particular that I am acknowledging my sincere feeling towards my mentors who
graciously gave me their time and expertise.
They have provided me with the valuable guidance sustained and friendly approach otherwise
it would have been difficult to achieve the results in such a short span of time without their
help.
I deem it my duty to record my gratitude towards my internal project supervisor Mr.
Hemendra who devoted her precious time to interact, guide, and gave me the right approach
to accomplish the task and also helped me to enhance my knowledge understanding of the
project.
Student:
Sarthak
BBA(G)
(5th SEMESTER)
2 Table in SQL
4
2.8 Display the details of employees
whose salary is b/w 5000&25000
2.9 Display details of employees
whose salaries are either 8000 or
13000
2.10 Display the details of employees
whose desig. is either clerk or
guard
2.11 Update the salary of the
employee to 6000 whose
employee_id is 7
2.12 Delete the column whose name is
salary
2.13 Add a column whose name is
mobile_no and data type is
number
2.14 Modify the table name to
dkpeace
5
2.23 Display the number of rows in
table kdpeace having count>2
2.24 Display the no. of distinct rows in
the designation column
2.25 Display the no. of rows in the
table kdpeace grouped by salary
2.26 Display the no. of rows in the
table kdpeace where
salary>=10000
3 Drop table
3.1 Delete table
3.2 Truncate table
INTRODUCTION TO SQL
What is SQL?
SQL stands for Structured Query Language. SQL is used to create, remove, alter the
database and database objects in a database management system and to store, retrieve,
update the data in a database. SQL is a standard language for creating, accessing,
manipulating database management system. SQL works for all modern relational
database management systems, like SQL Server, Oracle, MySQL, etc.
Types of SQL Commands
SQL commands are instructions. It is used to communicate with the database. It is also
used to perform specific tasks, functions, and queries of data.
SQL can perform various tasks like create a table, add data to tables, drop the table,
modify the table, set permission for users. There are five types of SQL commands:
DDL, DML, DCL, TCL, and DQL.
DDL
6
DDL stands for data definition language. DDL commands are used for creating and
altering the database and database object in the relational database management
system, like CREATE DATABASE, CREATE TABLE, ALTER TABLE, etc. The
most used DDL commands are CREATE, DROP, ALTER, and TRUNCATE.
CREATE
CREATE command is used to create a database and database object like a
table, index, view, trigger, stored procedure, etc.
Syntax: CREATE TABLE Employee (Id INT, Name VARHCAR(50), Address
VARCHAR (100));
ALTER
ALTER command is used to restructure the database object and the settings in the
database.
SYNTAX: ALTER TABLE Employee ADD Salary INT;
DROP
DROP command is used to remove the data and the database.
SYNTAX: DROP TABLE Employee
TRUNCATE
The TRUNCATE command is used to remove all the data from the table.
TRUNCATE command empties the table.
SYNTAX: TRUNCATE TABLE Employee
DML
DML stands for data manipulation language. DML commands are used for
manipulating data in a relational database management system. DML commands are
used for adding, removing, updating data in the database system, like INSERT INTO
Table Name, DELETE FROM Table Name, UPDATE table Name set data, etc. The
most used DML commands are INSERT INTO, DELETE FROM, UPDATE.
INSERT INTO
INSERT INTO commands is used to add the data in the database.
UPDATE
7
UPDATE is used to update the data in the database table.
DELETE
DELETE command is used to delete the data from the database table.
DCL
DCL stands for data control language. DCL commands are used for providing and
taking back the access rights on the database and database objects. DCL command
used for controlling user’s access on the data. Most used DCL commands are GRANT
and REVOKE.
GRANT
GRANT is used to provide access right to the user.
Syntax: GRANT INSERT, DELETE ON Employee TO user;
REVOKE
REVOKE command is used to take back access right from the user, it cancels access
right of the user from the database object.
TCL
TCL stands for transaction control language. TCL commands are used for handling
transactions in the database. Transactions ensure data integrity in the multi-user
environment. TCL commands can rollback and commit data modification in the
database. The most used TCL commands are COMMIT, ROLLBACK, SAVEPOINT,
and SET TRANSACTION.
COMMIT
COMMIT command is used to save or apply the modifications in the database.
ROLLBACK
ROLLBACK command is used to undo the modification in the database.
SAVEPOINT
SAVEPOINT command is used to temporarily save a transaction, the transaction can
roll back to this point when it's needed.
DQL
DQL stands for the data query language. DQL command is used for fetching the data.
DQL command is used for selecting data from the table, view, temp table, table
variable, etc. There is only one command under DQL which is the SELECT
command.
SYNTAX: SELECT * FROM Employee;
8
9
TABLE IN SQL
10
2. Describe the table kdpeace.
11
4. Display the details of all the employees
12
6. Display the details of employees whose designation is Clerk
8. Display the details of employees whose salary is between 5000 and 25000.
9. Display the details of employees whose salaries are either 8000 or 13000
13
10. Display the details of employees whose designation is either Clerk or Guard.
14
11.Update the salary of the employee to 6000 whose employee id is 7
15
13. Add a column whose name is Mobile_No and data type is number.
14. Modify the data type of column whose name is designation to char(20)
16
15. Modify the table name to dkpeace.
17
18. Display the average salary in the table kdpeace.
19. . Display the sum of the salaries in the table kdpeace where designation is Clerk.
18
21. Display the sum of the salary where salary is >=15000 and group by designation.
22. Display the sum of the salaries in the table kdpeace having sum salary >=30000
19
25. Display the number of rows in the table kdpeace grouped by salary
26. Display the number of rows in the table kdpeace where salary >= 12000
20
DROP TABLE DHRUV_KUBBA02
21
Entity Relationship Model
• Entity-Relationship Model or simply ER Model is a high-level data model
diagram.
• In this model, we represent the real-world problem in the pictorial form to
make it easy for the stakeholders to understand.
• It is also very easy for the developers to understand the system by just looking
at the ER diagram. We use the ER diagram as a visual tool to represent an ER.
COMPONENETS OF ERD
Model. ER diagram has the following three components:
Entities: Entity is a real-world thing. It can be a person, place, or even a
concept. Example: Teachers, Students, Course, Building, Department, etc are
some of the entities of a School Management System.
Attributes: An entity contains a real-world property called attribute. This is
the characteristics of that attribute. Example: The entity teacher has the
property like teacher id, salary, age, etc.
Relationship: Relationship tells how two attributes are related
22
Representation of ERD
23
ER DIAGRAM FOR HOSPITAL MANAGEMENT SYSTEM
24