Você está na página 1de 18

DBMS LAB

Submitted To: Submitted By:


Mrs. Amita Dhingra Sudhanshu kumar

Assistant professor, Roll No:- 19545

UIET MDU, Rohtak CSE-1(4th Sem.)

1|P ag e
1.Introduction to SQL
Structure Query Language(SQL) is a database query language used for storing and
managing data in Relational DBMS. SQL was the first commercial language introduced
for E.F Cod’s Relational model of database. Today almost all RDBMS(MySQL, Oracle,
Informix, Sybase, MS Access) use SQL as the standard database query language. SQL
is used to perform all types of data operations in RDBMS.

SQL Command
SQL defines following ways to manipulate data stored in an RDBMS.

DDL: Data Definition Language

This includes changes to the structure of the table like creation of table, altering table,
deleting a table etc.

All DDL commands are auto-committed. That means it saves all the changes
permanently in the database.

Command Description

Create to create new table or database

Alter for alteration

Truncate delete data from table

Drop to drop a table

Rename to rename a table

2|P ag e
DML: Data Manipulation Language

DML commands are used for manipulating the data stored in the table and not the table
itself.

DML commands are not auto-committed. It means changes are not permanent to
database, they can be rolled back.

Command Description

Insert to insert a new row

Update to update existing row

Delete to delete a row

Merge merging two rows or two tables

TCL: Transaction Control Language

These commands are to keep a check on other commands and their affect on the
database. These commands can annul changes made by other commands by rolling the
data back to its original state. It can also make any temporary change permanent.

Command Description

commit to permanently save

rollback to undo change

3|P ag e
save point to save temporarily

DCL: Data Control Language

Data control language are the commands to grant and take back authority from any
database user.

Command Description

grant grant permission of right

revoke take back permission.

DQL: Data Query Language

Data query language is used to fetch data from tables based on conditions that we can
easily apply.

Command Description

Select retrieve records from one or more table

4|P ag e
Experiment – 02

Topic :-CREATE A TABLE AND INSERT VALUES INTO IT.


1.For creating a table :-

SYNTAX :-
Create table table_name(column1 datatype1,column2 datatype2,…) ;

2.For inserting values into the table :-

SYNTAX :-
Insert into table_name(column1,column2,..) values(value1,value2,…) ;

Example:-

3.For showing the table :-

SYNTAX :-
Show table_name;

Example:-

5|P ag e
6|P ag e
Experiment- 03
Topic :-TO STUDY USE OF ALTER,DESCRIBE AND DROP
STATEMENT.

2.For describing a table_name :-


SYNTAX :-
Desc table_name;

Example :-

1.For altering the table :-

SYNTAX :-
Alter table table_name drop colum1,column2,..;

Example : -

7|P ag e
8|P ag e
Experiment- 04
Topic :- TO STUDY USE OF Delete and update statement.
1.For deleting a statement :-

SYNTAX :-
DELETE FROM table_name WHERE condition;

Example :-

2.For updating :-

SYNTAX :-
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

Example :-

9|P ag e
Experiment-05
Topic :-TO STUDY USE OF VARIOUS QUERY PROCESSING
STATEMENT.

SYNTAX :-
:- SELECT *from table_name;

:- SELECT distinct colum1,.. from table_name;

:- SELECT column1,.. from table_name condition1;

Condition1 - >,<,>=,=>,<>,OR,NOT etc.

Example:-

10 | P a g e
Experiment- 06
Topic :-TO STUDY USE OF VARIOUS CHARACTER
FUNCTION.
Assume-Take string=”sudhanshu”

SYNTAX :-
:- SELECT length(“<your string>”) output from dual;

:- SELECT lower(“<your string>”) output from dual;

:- SELECT upper(“<your string>”) output from dual;

:- SELECT replace(“<your string>”,”<replacable string>”,”<raplace with


string>”) output from dual;

:- SELECT substr(“<your string>”,place1,place2) output from dual;

:-SELECT instr(“<your string>”,”string to find”) output from dual;

Example :-

11 | P a g e
Experiment – 07
Topic :- TO STUDY OF THE VARIOUS NUMBER FUNCTION.
SYNTAX :-
:- Select CEIL(value1) output from dual;

:- Select FLOOR(value2) output from dual;

:- Select ABS(value3) output from dual;

:- Select POWER(value4) output from dual;

:- Select MOD(value5) output from dual;

:- Select SIGN(value6) output from dual;

:- Select ROUND(value7) output from dual;

:- Select EXP(value8) output from dual;

:- Select SQRT(value9) output from dual;

Example :-

12 | P a g e
13 | P a g e
Experiment-08
Topic :- .TO STUDY THE USE VARIOUS GROUP
FUNCTION.

SYNTAX :-
:- Select MAX(column1) output from table_name;

:- Select MIN(column1) output from table_name;

Example :-

14 | P a g e
Experiment-09
Topic :-.TO STUDY THE USE OF JOIN FUNCTION.

SQL JOIN
A JOIN clause is used to combine rows from two or more tables, based on a
related column between them.

Different Types of SQL JOINs


Here are the different types of the JOINs in SQL:

• (INNER) JOIN: Returns records that have matching values in both


tables
• LEFT (OUTER) JOIN: Return all records from the left table, and the
matched records from the right table
• RIGHT (OUTER) JOIN: Return all records from the right table, and
the matched records from the left table
• FULL (OUTER) JOIN: Return all records when there is a match in
either left or right table

SYNTAX :-
Select colum1,colum2,..
FROM table1_name JOIN table1_name
ON table1_name.column1 = table2_name.column2;

Example :-

15 | P a g e
16 | P a g e
Experiment-10
Topic :- TO STUDY USE OF SET ORIENTED OPERATION.

The SQL UNION Operator


The UNION operator is used to combine the result-set of two or more SELECT
statements.

• Each SELECT statement within UNION must have the same number of
columns
• The columns must also have similar data types
• The columns in each SELECT statement must also be in the same order

SYNTAX :-
SELECT column_name(s) FROM table1
UNION
SELECT column_name(s) FROM table2;

Example :-

17 | P a g e
18 | P a g e

Você também pode gostar