ISM LAB FILE by Raman
ISM LAB FILE by Raman
NEW DELHI
SUBMITTED AT:
Delhi Metropolitan Education
1|Page
CERTIFICATE
(Signature of Faculty)
Ms. Pooja tripathi
Assistant Professor
2|Page
DECLARATION
I take this opportunity to express my profound gratitude and deep
regrets to my guidance Asst. Professor Ms. Pooja Tripathi for her
exemplary guidance, monitoring and constant encouragement
throughout the course of this project. The blessing, help and guidance
by her time to time shall carry me a long way in the journey of life on
which I am about to embark.
Last but not the least, my sincere thanks to my parents and friends for
the wholehearted support and encouragement.
Ramandeep Singh
03591201720
3|Page
INDEX
S.NO CONTENTS PG. NO T. SIGN
1 Introduction to SQL and types of datatypes 5
2 SQL DDL Commands with syntax & examples 5-8
3 SQL DML Commands with syntax & examples 8-9
4 Primary key and Foreign key constraints 9-12
5 Update command & Alter command 12-13
Command for ‘Order By’ & ‘Like’ clause 13-14
Command for Aggregate Functions 14-15
Command for operators – less than, greater 15-18
than, less than equal to, greater than equal
to, between, like, IN
6 Command for operators – and, or, not 18-19
7 Command for indexes and views 19-20
8 Command for Upper case, Lower case, 20-22
Substring, Replace
9 Command for concat, length, MONTH 22-23
DAYOFMONTH and YEAR
10 Create Employee table and run given 23-25
commands
11 Create Student table and run given 25-27
commands
12 Create Supplier table and Parts table and run 27-29
given commands
13 What do you understand by ER Modeling 30-32
14 Symbols of ER Model with examples 33
15 ER Diagram of an Organization 33
16 ER Diagram of a Banking System 34
17 ER Diagram of a Hospital Management 34
System
18 ER Diagram of a University 35
4|Page
ISM LAB FILE
1. Introduction to SQL. Explain different types of data types in
SQL.
Structured Query Language is a scripting language to access
databases.
It allows you to create or delete databases, fetch or modify
rows, etc.
It allows you to manipulate or retrieve data stored in a
database like MySQL, MS Access, Oracle, etc.
Some of its data types are following –
Numeric data type – it contains exact numeric digits
like integers, decimals, etc. as well as approximate
numeric digits like float, real, double precision, etc.
Date and Time data type – it contains values related to
date, time, timestamps, year, etc.
String data type – it contains text and binary data like
files, images, etc.
Binary Large Object data type – it can hold a variable
amount of data.
Spatial data type – it contains geometrical and
geographical values.
2. Explain SQL DDL commands with syntax and examples.
Data Definition Language (DDL) is a subcategory of SQL
which is used to define and work with database structure.
This include name of each table and database and their
connection. Some commands are –
CREATE – it is used to create new databases, tables, and
columns within tables.
5|Page
Syntax – create database name;
Example – create database sahil_kaku;
Syntax – create table name ( column1 data_type,
column2 data_type, ….);
Example – create table section_b (enroll int, name
varchar(20), age int);
SHOW – it is used to display a list of databases and tables in
a system.
Syntax – show databases;
Syntax – show tables;
USE – it is used to access databases to create tables in in
them.
Syntax – use database name;
Example – use sahil_kaku;
DESCRIBE – it is used to describe the content of a table.
Syntax – desc table name;
Example – desc section_b;
ALTER – it is used make changes in a table like add/delete
columns, rename table, delete table, etc.
Syntax (to add column) – alter table table_name add
column attribute_name data type;
Example – alter table section_b add column branch
varchar(15);
Syntax (to delete column) – alter table table_name
drop column attribute_name;
Example – alter table section_b drop column branch;
Syntax (to rename table) – alter table table_name
rename new_name;
6|Page
Example – alter table section_b rename bba4;
Syntax (to delete table) - drop table table_name;
Example - drop table bba4;
7|Page
3. Explain SQL DML commands with syntax and examples.
INSERT – it is used to insert new values in table.
Syntax – insert into table_name ( value1, value2,…)
Values (‘value1’, ‘value2’, ….);
Example – insert into section_b (enroll, name, age)
Values (‘101’, ‘sahil’, ‘20’);
SELECT – it is used to select data from the table. Different
condition can be used with this command.
Syntax – select * from table_name where clause;
Example – select * from section_b;
UPDATE – it is used to make changes in the values.
Syntax – update table_name set attribute = value
where clause;
Example – update section_b set name=’etisha’ where
enroll= ‘106’;
DELETE – it is used to delete values from the table.
Syntax – delete from table_name where clause;
8|Page
Example – delete from section_b where name=
‘etisha’;
9|Page
Some conditions of primary key are –
Insert records with distinctive values of roll no.
Insert record where roll no. is same as any other and all
other values different
Note – the query won’t be completed because primary key
(roll no.) contains duplicate value.
Insert record where roll no. is different and all other values
same as any other.
10 | P a g e
Foreign Key constraint is used to prevent actions that would
destroy link between tables
Syntax – foreign key (column name from foreign table)
reference primary table name (primary key of primary table)
Example – foreign key (player) reference bba4b (roll_no)
Not Null constraint is used to ensure the given column of the
table never assign a null value.
Syntax – column_name datatype not null
Example – name varchar(20) not null
11 | P a g e
Delete from table games where player=1
Note – if we delete the record from table bba4b first, then it
will show an error ‘foreign key constraint fails’. To do so, first
we have to delete the record from foreign table.
12 | P a g e
Example – alter table bba4b drop column branch;
Syntax (to rename table) – alter table table_name
rename new_name;
Example – alter table bba4b rename bba_4b;
Syntax (to delete table) - drop table table_name;
Example - drop table games;
13 | P a g e
Write command for aggregate functions
14 | P a g e
Sum - this is used to find out total of all the entries recorded
in a table.
Syntax – select sum(column) from table_name
Example – select sum(marks) from bba_4b
Less than – this operator is used to find all the values lower
than the certain value of the column.
Syntax – select * from table_name where
column<’limit’
Example – select * from bba_4b where marks<’92’;
Greater than – this operator is used to find all the values
higher than the certain value of the column.
15 | P a g e
Syntax – select * from table_name where
column>’limit’
Example – select * from bba_4b where marks>’90’;
Less than equal to - this operator is used to find all the
values either lower than or equal to the certain value of the
column.
Syntax – select * from table_name where
column<=’limit’
Example – select * from bba_4b where marks<=’92’;
Greater than equal to - this operator is used to find all the
values either higher than or equal to the certain value of the
column.
Syntax – select * from table_name where
column>=’limit’
Example – select * from bba_4b where marks>=’90’;
16 | P a g e
Between – this operator is to find number of values lying
between 2 certain values.
Syntax – select * from table_name where column
between ’limit’ and ’limit’
Example – select * from bba_4b where marks between
’88’ and ‘94’
Like – this is used in a WHERE clause to search for a specific
pattern in a column.
Syntax – select column from table_name where
column like ‘_%’
Example – select * from bba_4b where name like ‘p%’
17 | P a g e
IN – this is used to specify multiple values in a WHERE
clause.
Syntax – select * from table_name where column IN
(value1, value2….)
18 | P a g e
OR – it is used when to fulfill any one of the condition to run
a command.
Syntax – select * from table_name where clause1 or
clause2.
Example – select * from bba_4b where roll_no=’4’ or
name=’paras’
NOT – it is used when to reject a condition in a command
Syntax – select * from table_name where not clause1.
Example – select * from bba_4b where not
name=’paras’
19 | P a g e
An index is used to speed up select queries and where
clauses.
Syntax – create INDEX index_name
on table_name (column1, column2,…)
Example – create INDEX roll_name
On bba_4b (roll_no, name)
Views in SQL are considered as virtual table and also contain
rows and columns.
A view can either have specific row based on certain
condition or all the rows of a table.
Syntax – create VIEW view_name as select * from
table_name where condition
Example - create VIEW details as select * from bba_4b
where roll_name=’5’
20 | P a g e
LOWERCASE – this command is to present the data in small
letters (lowercase).
Syntax – select lower(column) from table_name
Example – select lower(name) from bba_4b
SUBSTRING – this command is used to present only certain
characters of the value of the column from the table.
Syntax – select substring (column, direction of letters,
number of letters) from table_name
Example – select substring (name, 1, 3) from bba_4b
Note – the (1, 3) means the first 3 letters of the name
REPLACE – this command is used to change the case of
letter in a particular column
Syntax – select replace (column, ’old letter’, ‘new
letter’) from table_name where condition
Example – select replace (name, ‘p’, ‘P’) from bba_4b
where name=’prajjwal’ and name=’paras’
21 | P a g e
9. Write command for
CONCAT – this command is used to add two or more strings
(words) or columns together.
Syntax – select concat (string1, string2,…)
Example – select concat (‘sql’, ‘ ‘, ‘is’, ‘ ‘, ‘fun’)
LENGTH – this command return length of strings in bytes,
i.e. number of letters in a string.
Syntax – select length (string)
Example – select length (“SQL Tutorial”) as
lengthofstring;
MONTH, DAYOFMONTH and YEAR – this command is used
to extract month, day, and year from any given date.
Syntax – select DAYOFMONTH(column) as ‘name’,
MONTH(column) as ‘name’, YEAR(column) as ‘name’
from table_name;
Example - select DAYOFMONTH(birth_date) as ‘day’,
MONTH(birth_date) as ‘month’, YEAR(birth_date) as
‘year’ from bba_4b;
22 | P a g e
10. Create employee table and perform following commands.
a) Eid, ename, desg, branch, salary, address.
b) Insert 10 records.
c) List employees whose salary is between 10,000 & 30,000.
d) Ename sould be unique.
e) Add column in table – date of joining, experience.
f) Delete column desg.
g) Find out details of employees whose salary is above 25,000.
h) Calculate total no. of records in employee table.
23 | P a g e
List employees whose salary is between 10,000 -30,000.
24 | P a g e
Total no. of records in employee table.
25 | P a g e
Student name where age is greater than 18 and course MBA
26 | P a g e
the name of student by roll no. in descending order.
27 | P a g e
Supplier table –
Parts table –
28 | P a g e
29 | P a g e
13. What do you understand by ER Modeling?
Entity Relationship(ER) model is a concept that describes the
structure of database with the help of a diagram called Entity
Relationship(ER) diagram.
ER model is a blueprint or a design of the database that can be
implemented on the database later on.
Components of
Entity Relation
ER model ship
Attribute
30 | P a g e
Pin code
Name Student Address
State
Phone n.
Age
Work
Student Student
with
31 | P a g e
College has Student
Student Go to College
32 | P a g e
14. Explain all the symbols of ER model with
examples.
RECTANGLES – they are used to represent entities. Ex –
students, college, staff, faculty, etc.
ELLIPSES – they are used to represent attributes. Ex – names,
roll no., course, city, pin code, etc.
DIAMONDS – they are used to represent relationships. Ex –
work, has, go to, enrolls, etc.
LINES – it links attributes to their entities and entities with their
relationships.
PRIMARY KEY – they are the attributes which are underlined
and unique.
DOUBLE ELLIPSES – they are the multivalued attributes. Ex –
phone no., email ids, etc.
15. Draw ER diagram of an organization.
Name Address
has
has
Name Address
has
Cash
Address Name Type limit Address
Balance
use
Qualification
treats
Room no. Type Name Usage
Name Pat. id
Name
University provide
Address
has
Name
has Colleges
Address
has
Name Salary Name S. id Name Subjects
35 | P a g e