0% found this document useful (0 votes)
14 views16 pages

DBMS_LAB_HIMANSHU_KAUSHIK_21CSE028-1

Lab file Of dbms
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views16 pages

DBMS_LAB_HIMANSHU_KAUSHIK_21CSE028-1

Lab file Of dbms
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

GANGA INSTITUTE OF

TECHNOLOGY AND MANAGEMENT


(KABLANA)

Department of Computer Science and Engineering


SUBMITTED BY: SUBMITTED TO:
Aditya
HIMANSHU KAUSHIK Dr. Kavita
B.TECH (3rd SEM) Assistant Professor
21CSE005
21CSE028 CSE Department
PRACTICAL NO. 1

AIM:-Exercise on creation of Table.

SYNTAX:- create table table_name (column_name


datatype(size),column_name datatype(size));

EXAMPLE1:- Create a table Student whose structure are as follows:-

SQL> create table Student (name varchar(10), rollno tinyint,class


varchar(10),address varchar(20));
Result:- SQL query successfully executed. However, the result set is empty.

EXAMPLE2:- Create a table Employee whose structure are as follows:-

SQL> create table Employee (name varchar(20),designation


varchar(20),shift varchar(10),salary int, address varchar(20));
Result:- SQL query successfully executed. However, the result set is empty.

PRACTICAL NO. 1

AIM:- Exercise on creation of Table.

Structure of the table student:-


Student [-]
​ name[varchar(10)]
​ rollno[tinyint]
​ class[varchar(10)]
​ address[varchar(20)]

Structure of the table employee:-


Employee [-]
​ name[varchar(20)]
​ designation[varchar(20)]
​ shift[varchar(10)]
​ salary[int]
​ address[varchar(20)]
PRACTICAL NO. 2

AIM:- Exercise on insertion of a data into Table.

Method1:- Syntax of insertion of data into a table by Direct method :-

SYNTAX:- insert into table name (column name1, column name2) values
(value1,value2);

Example:- Insert the following data into table student :-


SQL> insert into student values(‘Aditya’,5, ‘CSE’, ‘Jhajjar’);
Result:- SQL query successfully executed. However, the result set is
empty.

Method2:- Syntax of insertion of data in table by Substitution method :-


SYNTAX:- insert into table name values(‘&column1’, ‘&column2’);

Example:- Insert the following data into the table Employee.


SQL> insert into Employee values ('&name' ,'&designation', '&shift',
&salary , '&address');

Enter the value for name : Aditya


Enter the value for designation : Product Designer
Enter the value for shift : Morning
Enter the value for salary : 8000000
Enter the value for address : Jhajjar
1 row created.

SQL> /
Enter the value for name : Bhupesh
Enter the value for designation : Security Incharge
Enter the value for shift : Morning
Enter the value for salary : 800000
Enter the value for address : B.garh
1 row created.

SQL> / (then do again and again if you want to enter some other
values)
Result:- SQL query successfully executed. However, the result set is
empty.
PRACTICAL NO. 2

AIM:- Exercise on insertion of a data into Table.

Method1:- Direct method :-

Student
name rollno class address

Aditya 5 cse jhajjar

Bhupesh 90 B.S.C B.garh

Method2:- Substitution method :-

Employee
name designation shift salary address

Aditya Product morning 8000000 Jhajjar


Designer

Bhupesh security morning 800000 B.garh


incharge

RESULT:- Insertion of a data in the table is successfully completed

PRACTICAL NO. 3

AIM:- Exercise on different forms of “SELECT” statement.

SYNTAX:- select * from table name;


EXAMPLE 1:- Display all the rows and all the columns from the table
student.
SQL> select * from student;

SYNTAX :- Syntax for accessing selected columns and all rows from a table :-
select column1,column2,column3 from table name;
EXAMPLE 2:- Display name,rollno from Student.
SQL> select name, rollno from student;

SYNTAX:- Syntax for elimination of duplicacy of a data from the table :-


select distinct from table name;
EXAMPLE 3:- Elimination of duplicacy of data from the table Student.
SQL> select distinct name from student;

SYNTAX:- Syntax of selected rows with all columns :-


select * from table_name where condition coloumnname;
EXAMPLE 4:- Display the selected row with all columns from the table
student :-
SQL> select * from student where rollno=5;

SYNTAX:- Syntax of selected rows with selected columns :-


select column name from table name where condition;
EXAMPLE 5:- Display the selected rows & columns from the table student.
SQL> select name from student where class= "cse";

SYNTAX:- Display data in an ordered form using where condition :-


select column1,column2 from table name [where condition]
order by column name;
EXAMPLE 6:- Display name,city from the table name employee where the
city is B.garh and order by name.
SQL> select name,shift from employee where city=‘B.garh’ order by
name;

SYNTAX:- Display data in an ordered form :-


select * from table name order by column name;
EXAMPLE 7 :- sorting :=> ordering in table student :-
SQL> select * from student order by name desc;

RESULT:- SELECT command is successfully completed.

PRACTICAL NO. 3

AIM:- Exercise on Select statement.

1) To display all the data in table:-


Student
name rollno class address

Aditya 5 cse jhajjar

Bhupesh 90 B.S.C B.garh

Aditya 5 cse jhajjar

2) To display name, rollno from table:-

Student
name rollno

Aditya 5

Bhupesh 90

Aditya 5

3) To eliminate the duplication of data :-

Student
name rollno

Aditya 5

Bhupesh 90

4) To display different data in a column name :-

Student
name rollno class

Aditya 5 cse

Bhupesh 90 B.S.C
Aditya 5 cse

5) To display name from table where department is cse :-

Student
name

Aditya

Aditya

6) To display all data in table student in descending order by name:-

Student
name rollno class address

Bhupesh 90 B.S.C B.garh

Aditya 5 cse jhajjar

Aditya 5 cse jhajjar

RESULT:- SELECT command is successfully completed

PRACTICAL NO.4

AIM:-Exercise on Deletion of data from the table using different conditions.

SYNAX:- Syntax of Deletion of all the rows from the table :-


Delete from table name;
EXAMPLE:- Delete all the rows from the table Student.
SQL> DELETE from student;

SYNTAX:- Syntax for Deletion of the specific rows from the table :-
Delete from table name where condition;
EXAMPLE:- Delete from the table Employee where address is B.garh.
SQL> DELETE from Employee Where address=’B.garh’;

RESULT:- Exercise on Deletion of data from the table using different


condition has been successfully completed

PRACTICAL NO.4

AIM:- Exercise on Deletion of data from the table using different conditions.

1) To Delete all the rows from the table Student:-


2 rows deleted.

2) To Delete all the rows from the table Student:-


1 row deleted.

RESULT:- Exercise on Deletion of data from the table using different


condition has been successfully completed

PRACTICAL NO. 5

Aim:- Exercise on Update statement.

THEORY:- The update statement is used to change or modify the data


values into the table.

SYNTAX:- Syntax for updating all the rows in a table.


Update table name set column_name1=‘value’,column_name2=‘value’;
EXAMPLE 1:- Update the table Employee.Increase the value of field salary
with 100%
SQL> UPDATE Employee set salary=salary*2;

SYNTAX:- Syntax for Updating the selected rows in a table.


UPDATE table name set column_name1 =‘value’,column_name2
=‘value’, Column_name3=‘value’ where column_name =‘value’;
EXAMPLE 2:- UPDATE the table student.Change the contents of the field
Rollno to 777,field class to EC and Address to Delhi record identity by the field
name containing the value Aditya.
SQL> UPDATE Student set Rollno=777,class=’EC’,Address=’Delhi’
where name=’Aditya’;
RESULT:- Updating of data into table Employee and Student is
successfully completed.

PRACTICAL NO. 5

AIM:- Exercise on Update statement.

1) Exercise on UPDATE all rows of the table.


2 rows updated.

2) Exercise on UPDATE selected rows of the table.


1 row updated.

RESULT:- Updating of data into table Employee and Student is successfully


completed.

PRACTICAL NO. 6

AIM:- Exercise on GROUP, SCALAR and CONVERSION Functions.

GROUP FUNCTIONS OR AGGREGATE FUNCTIONS :- It can basically perform


with a set of rows or values Functions.

AVERAGE(AVG):- AVG is used for returning average value of ‘n’ record and
ignoring null values.
Syntax:- select avg(expr) from table name;
SQL> select avg(salary) “Average” from Employee;

Minimum(min):- Returns the minimum value of ‘expr’ or column.


Syntax:- select min(expr) from table name;
SQL> select min(salary) “ Minimum” from Employee;

Maximum(max):- Returns the maximum value of ‘expr’ or column.


Syntax:- select max(expr) from table name;
SQL> select max(salary)“Maximum” from Employee;

Sum:- Returns sum of values of ‘n’ rows.


Syntax:- select sum(expr) from table name;
SQL> select sum(salary) from Employee;
Count(expr) :- Returns the numbers of rows where ‘expr’ is not null.
Syntax :- select count(expr) from table name;
SQL> select count(name) from employee;

Count(*) :- Returns the number of rows in the table, including


duplicates and those with null.
Syntax :- select count(*) from table name;
SQL> select count(*) from employee;

Scalar Functions Or Sigle Row Functions:- It can basically to perform a single


row or value functions.

ABS:- It returns the absolute value of ‘n’. The Scalar Functions use a
default table called “dual”.
Syntax :- ABS(n)
SQL> select abs(-15) “absolute” from employee;

POWER:- It returns the powered value or returns ‘m’ raise to ‘n’ power. ‘n’
must be an integer value.
Syntax :- Power(m,n)
SQL> select power(3,3) ”Power” from employee;

ROUND:- It returns the n rounded to ‘m’ places right to the decimal point. If
‘m’ is omitted, ‘n’ is rounded to ‘0’. ‘m’ can be negative to round off digits left to
the decimal point. ‘m’ must be an integer.
Syntax :- ROUND(n,m)
SQL> select round(7.16,1) from employee;

SQRT:- It returns the square root of ‘n’ . If n<0, Null, SQRT return a real
result.
SQL> select sqrt(25) “square_root” from employee;

String function :-

LOWER :- Returns char, with all letters in lowercase.


Syntax :- lower(char)
SQL> select lower(‘Aditya’) from employee;

UPPER :- Returns char, with all letters forced to uppercase.


Syntax :- upper(char)
SQL> select upper(‘Aditya’) from employee;

INITCAP :- Returns strings with the first letters uppercase.


Syntax :- initcap(char)
SQL> select initcap(‘Aditya’) from employee;

LPAD :- Returns ‘char1’ left padded to length ‘n’ with the sequence of
character in ‘char2’. ‘Char2’ default to blank.
Syntax :- LPAD(char1,n,char2)
SQL> select lpad(‘aditya’,10,‘*’);

CONVERSION FUNCTIONS:- It convert a value of number data into a value of


char datatype.

TO CHAR:- It convert a value of number datatype to a char datatype .


SQL> select To_Char(17145, ‘$099,999’) “CHAR” from employee;

RESULT:- Exercise on GROUP, SCALAR and CONVERSION Functions is


successfully Completed.

PRACTICAL NO. 6

AIM:- Exercise on GROUP, SCALAR and CONVERSION Functions

Group Functions Output:-

1) AVG(SALARY)
Average

4400000

2) MIN(SALARY)
Minimum Salary

1600000

3) MAX(SALARY)
Maximum Salary
16000000

4) SUM(SALARY)
Salary Sum

17600000

5) COUNT(NAME)
count(name)

6) COUNT(*)
count(*)

Scalar Functions Output :-

1) ABS(-15)
absolute

15

15

2) POWER(3,3)
power

27

27

3) ROUND(7.16,1)
round

7.2

7.2
4) SQRT(25)
square root

String Functions Output :-

1) LOWER
lower(“name”)

aditya

bhupesh

2) UPPER
upper(“name”)

ADITYA

BHUPESH

3) INIT
init(“name”)

Aditya

Bhupesh

4) LPAD(‘Aditya’)
lpad(‘aditya’)

****Aditya

CONVERSION Function Output :-

1) TO_CHAR
to_char

16000000

1600000

RESULT:- Exercise on GROUP, SCALAR and CONVERSION Functions is


successfully Completed.

PRACTICAL NO. 7

AIM:- Exercise on creation of table using constraints.

The constraints enforced the rules to prevent the user to enter the invalid data
in the table.

The constraints have two levels :-


1) Table level
2) Column level

PRIMARY KEY

1) Column level
Syntax :- column_name datatype(size) primary key;

Example :- Create a table Employee2 and use Primary Constraint at the


column level.
SQL> create table Employee2(rollno number(12) primary key, name
varchar(12));

At Column level,we can apply only one primary key on one column.

2) Table level
Syntax :- primary key(columnname1,columnname2…..columnname n);

Example :- Create a table Employee2 and use Primary Constraint at the


Table level.
SQL> create table Employee2(name varchar(12), rollno number(12),
primary key(name,rollno));
At Table level, we can apply primary key on multiple columns.

NOT NULL Constraint

1) Column level
Syntax :- columnname datatype(size) not null;

Example :- Create a table Employee2 and use Not Null Constraint at the
column level.
SQL> create table Aarti(name varchar(12)not null, rollno number(12));

Not Null Constraint can be applied only at the column level.

UNIQUE Constraint

1) Column level
Syntax :- columnname datatype(size) unique;

Example :- Create a table Employee2 and use Unique Constraint at the


column level.
SQL> create table Employee2( rollno number(12) unique, name
varchar(12));

2) Table level
Syntax :- unique(columnname,[columnname,- - - - - ]);

Example :- Create a table Employee2 and use Unique Constraint at the


Table level.
SQL> create table Employee2(name varchar(12), rollno
number(12), unique(name,rollno));

RESULT:- Exercise on creation of table using constraints have been


successfully completed.

PRACTICAL NO. 7

AIM:- Exercise on creation of table using constraints.

PRIMARY KEY
Structure of the Employee2 using Primary constraint at column level and Table
level
SQL> describe Employee2;
Employee2 [-]
​ name[varchar(12)][not null]
​ rollno[varchar(12)]

NOT NULL Constraint

Structure of the Employee2 using Not Null constraint at column and Table level.
SQL> describe Employee2;
Employee2 [-]
​ name[varchar(12)][not null]
​ rollno[varchar(12)]

UNIQUE Constraint

Structure of the Employee2 using Unique at column level & Table level.
SQL> describe Employee2;
Employee2 [-]
​ name[varchar(12)][unique]
​ rollno[varchar(12)][unique]

RESULT:- Exercise on creation of table using constraints have been


successfully completed.

You might also like