Karan ISM File
Karan ISM File
This is to certify that ISM Practical lab File is the original work of KARAN SINGH
(01124301722) student of BBA(G) 5th semester and has duly completed her project under my
guidance and supervision to my satisfactory level. This work has been done in partial
fulfillment of the requirement for the award of the degree of Bachelor of Business
Administration from SIRIFORT INSTITUTE OF MANAGEMENT STUDIES, GGSIPU and
has not been submitted in any other university for the award of any degree.
2
ACKNOWLEDGMENT
It is not possible to prepare the project report without the assistance and encouragements
of other people. This one is certainly no exception.
On the very outset of this report, I would like to extend my sincere and heartfelt obligation
towards all the personages who have helped me in this endeavor. Without their active
guidance, help, cooperation and encouragement. I would not have headway in the project.
I am extremely thankful and pay my gratitude to my faculty MR. ANUKOOL BAJPAI for
his valuable guidance and support on completion of this project in it presently.
I also acknowledge with a deep sense of reverence, my gratitude towards my parents and
my friends, who has always supported me morally.
Any omission in this brief acknowledgment does not mean lack of gratitude.
Thanking You
KARAN SINGH
3
INDEX
4
Question 1: Introduction to SQL. Explain what different types of data types in SQL are.
SQL (Structured Query Language) is a domain-specific language used in programming and designed for
managing data held in a relational database management system (RDBMS), or for stream processing in a
relational data stream management system (RDSMS). It is particularly useful in handling structured data, i.e.
data incorporating relations among entities and variables.
SQL (Structured Query Language) is a database sublanguage for querying and modifying relational databases. It
was developed by IBM Institutes)
in 1986.
The Structured Query Language (SQL) is a language of databases. All modern relational databases, including
Access, FileMaker pro, Microsoft SQL Server and Oracle use SQL as their basic building block. All of the
graphical user interfaces that provide data entry and manipulation functionality are nothing more than SQL
translators. They take the actions you perform graphically and convert them to SQL commands understood by
the database. Using SQL, you can insert records, update records, and delete records. You can also create new
database objects such as databases and tables. And you can drop (delete) them.
SQL offers two main advantages over older read write APIs such as ISAM or VSAM. Firstly, it introduced the
concept of accessing many records with one single command. Secondly, it eliminates the need to specify how to
reach a record, e.g. with or without an index.
Originally based upon relational algebra and tuple relational calculus, SQL consists of many types of statements,
which may be informally classed as sub languages, commonly: a data query language (DQL), a data definition
language (DDL), a data control language (DCL), and a data manipulation language (DML). The scope of SQL
includes data query, data manipulation (insert, update and delete), data definition (schema creation and
modification), and data access control. Although SQL is essentially a declarative language (4GL), it includes also
procedural elements.
SQL was one of the first commercial languages to utilize Edgar F.Codd relational model. The model was
described in his influential 1970 paper, "A Relational Model of Data for Large Shared Data Banks". Despite not
entirely adhering to the relational model as described by Codd, it became the most widely used database language.
History
SQL was initially developed at IBM by Donald D. Chamberlin and Raymond F. Boyce after learning about the
relational model from Ted Codd in the early 1970s. This version, initially called SEQUEL (Structured English
Query Language), was designed to manipulate and retrieve data stored in IBM's original quasirelational
5
database management system, System R, which a group at IBM San Jose Research Laboratory had developed
during the 1970s.
Chamberlin and Boyce's first attempt of a relational database language was Square, but it was difficult to use
due to subscript notation. After moving to the San Jose Research Laboratory in 1973, they began work on
SEQUEL. The acronym SEQUEL was later changed to SQL because "SEQUEL" was a trademark of the UK-
based Hawker Siddeley Dynamics Engineering Limited company. After testing SQL at customer test sites to
determine the usefulness and practicality of the system, IBM began developing commercial products based on
their System R prototype including System/38, SQL/DS, and DB2, which were commercially available in
1979, 1981, and 1983, respectively.
In the late 1970s, Relational Software, Inc. (now Oracle Corporation) saw the potential of the concepts
described by Codd, Chamberlin, and Boyce, and developed their own SQL-based RDMS with aspirations of
selling it to the U.S. Navy, Central Intelligence Agency, and other U.S. government agencies. In June 1979,
Relational Software, Inc. introduced the first commercially available implementation of SQL, Oracle V2
(Version2) for VAX computers.
By 1986, ANSI and ISO standard groups officially adopted the standard "Database Language SQL" language
definition. New versions of the standard were published in 1989, 1992, 1996, 1999, 2003, 2006, 2008, 2011]
and, most recently, 2016.
Design
SQL deviates in several ways from its theoretical foundation, the relational model and its tuple calculus. In that
model, a table is a set of tuples, while in SQL, tables and query results are lists of rows: the same row may
occur multiple times, and the order of rows can be employed in queries (e.g. in the LIMIT clause).Critics argue
that SQL should be replaced with a language that returns strictly to the original foundation: for example, see
The Third Manifesto. However, no known proof exists that such uniqueness cannot be added to SQL itself, or at
least a variation of SQL. In other words, it's quite possible that SQL can be "fixed" or at least improved in this
regard such that the industry may not have to switch to a completely different query language to obtain
uniqueness. Debate on this remains open.
1. Numeric data types such as int, tinyint, bigint, float, real etc.
2. Date and Time data types such as Date, Time, Datetime etc.
3. Character and String data types such as char, varchar, text etc.
4. Unicode character string data types, for example nchar, nvarchar, ntext etc.
5. Binary data types such as binary, varbinary etc.
Miscellaneous data types clob, blob, xml, cursor, table etc.
7
8
The following table lists the general data types in SQL: -
CHARACTER(n)- Character string. Fixed-length n
VARCHAR(n) or CHARACTER VARYING(n)- Character string. Variable length. Maximum
length n
BINARY(n)- Binary string. Fixed-length n
BOOLEAN- Stores TRUE or FALSE values
VARBINARY(n) or BINARY VARYING(n)- Binary string. Variable length. Maximum length n
INTEGER(p)- Integer numerical (no decimal). Precision p
SMALLINT- Integer numerical (no decimal). Precision 5
EIGINT- Integer numerical (no decimal). Precision 19
9
Question 2: Explain SQL DDL Commands. With Syntax and Examples.
The Data Definition Language (DDL) is used to create and destroy databases and databases objects. These
SQL statements define the structure of a database, including rows, columns, tables, indexes, and databases
specifics such as file locations.
CREATE To create objects in the database.
ALTER Alters the structure of the database.
TRUNCATE is used to remove all records from a table, including all spaces allocated for the records
are removed.
COMMENT is used to add comments to the data dictionary.
RENAME is used to rename an object existing in the database. The create
table command: -
The create table command defines each column of the table uniquely. Each column has minimum of three
attributes.
• Name
• Data type
• Size (column width).
Each table column definition is a single clause in the create table syntax. Each table column definition is
separated from the other by a comma. Finally, the SQL statement is terminated with a semicolon.
The Structure of Create Table Command Table
name is Student
Column name Data type Size
Reg_no varchar2 10
Name Char 30
DOB Date
Address varchar2 50
Example:
CREATE TABLE Student
10
(Reg_no varchar2(10),
Name char (30),
DOB date,
Address varchar2(50));
Example:
DROP TABLE Student;
It will destroy the table and all data which will be recorded in it.
Example:
TRUNCATE TABLE Student;
Example:
RENAME <Student> TO <Stu>
The old name table was Student now new name is the Stu.
11
ADD (<NewColumnName> <Data_Type>(<size>),......n)
Example:
ALTER TABLE Student ADD (Age number(2), Marks number(3));
The Student table is already existing and then we added two more columns Age and Marks respectively, by
the use of above command.
Example:
ALTER TABLE Student MODIFY (Name Varchar2(40));
The Name column already exist in Student table, it was char and size 30, now it is modified by Varchar2 and
size 40.
Restriction on the ALTER TABLE
Using the ALTER TABLE clause the following tasks cannot be performed.
Change the name of the table
Change the name of the column
Decrease the size of a column if table data exists .
12
13
SET Syntax
Example
The following example delete the record where EID equals to 10 from the Employee table, DELETE from
Employee WHERE EID=10;
Question 4: Create a table named Customer (C_id, C_name, Address, city, pin code, Country). Insert at least
10 values. Display the table.
➢ insert into customer value(01, 'pradip', '2/22 shastri park', 'New delhi', 110212, 'India');
➢ insert into customer value(02, 'ishan', '2/23 rohini', 'New delhi', 110213, 'India');
➢ insert into customer value(03, 'gaurav', '2/24 rohini sec 10', 'New delhi', 110214,
'India');
➢ insert into customer value(04, 'nikhil', '2/25 welcome', 'New delhi', 110215, 'India');
➢ insert into customer value(05, 'sagar', '2/26 tila mor', 'ghaziabad', 110216, 'India');
➢ insert into customer value(06, 'pranav', '2/27 dilshad garden', 'New delhi', 110216,
'India');
➢ insert into customer value(07, 'naman', '2/28 welcome', 'New delhi', 110217, 'India');
➢ insert into customer value(08, 'himanshu', '2/29 dwarka', 'New delhi', 110218, 'India');
➢ insert into customer value(09, 'vishal', '2/30 rohini sec 24', 'New delhi', 110219,
'India');
➢ insert into customer value(10, 'faiz', '2/31 kalkaji', 'New delhi', 110220, 'India');
select * from customer;
14
Question 5: Create table named Employee containing columns (emp_id, emp_name, emp_desig, DOB, emp_sal,
emp_dept). Insert atleast 10 values.
15
insert into employee values(01, 'AB', 'marketing manager', '1990/01/10', 50000, 'marketing');
insert into employee values(02, 'BA', 'HR manager', '1991/02/11', 60000, 'HR'); insert into
employee values(03, 'CD', 'finance manager', '1992/03/12', 70000, 'finance'); insert into
employee values(04, 'DE', 'production manager', '1993/04/13', 80000, 'production'); insert into
employee values(05, 'EF', 'investment manager', '1994/05/14', 90000, 'investment'); insert into
employee values(06, 'FG', 'sales manager', '1995/06/15', 100000, 'sales'); insert into employee
values(07, 'GH', 'purchase manager', '1996/07/16', 110000, 'purchase'); insert into employee
values(08, 'HI', 'Research manager', '1997/08/17', 120000, 'Research'); insert into employee
values(09, 'IJ', 'Promotion manager', '1998/09/18', 130000, 'promotion'); insert into employee
values(10, 'JK', 'Operations manager', '1999/10/19', 140000, 'operational');
16
Question 6: Create Employee table: -
Insert 10 Records.
17
values(9, 'Vivek', 'finance manager', 'Shalimar garden', 100000, 2/24 insert into employee
values(10, 'Abhay', 'factory head', 'shastri nagar', 110000, 2/248);
18
select * from employee;
19
2. Complete the Table Definition
4. Find out details of employee whose salary is above 25000. select * from employee where
salary>25000;
20
5. Find out details of employee order by salary. select * from employee order by salary;
21
select * from employee where salary between 10000 and 30000;
Question 7: Create the following table and perform SQL commands. Student (Roll_no, name, age, course,
marks).
1. List all those students who are greater than 18 years of age and have opted for MBA course.
2.
3. Find out total number of records in table.
4. Find out the name, course, marks and sort in the order of marks.
5. Display name and course of student.
6. Find the Student with Max marks.
7. List the name of students ORDER BY Roll_no in Descending order.
8. Find out the Average of all the Marks. Display it as Average_Marks.
create database st1; use st1; create table student(roll_no int, name varchar(20), age int,
course varchar(10), marks int);
insert into student values(1 'pradip', 20, 'mba', 90); insert
into student values(2, 'ishan', 19, 'bba', 80); insert into
student values(3, 'gaurav', 20, 'mba', 85); insert into
student values(4, 'nikhil', 21, 'bcom', 75); insert into
student values(5, 'aditi', 18, 'bba', 60); select * from
student;
1. List all those students who are greater than 18 years of age and have opted for MBA
course.
22
select * from student where age>18 and course= 'mba';
2.
23
4. Find out the name, course, marks and sort in the order of marks.
24
7. List the name of students ORDER BY Roll_no in Descending order.
25
Question8: Create the Following Tables. Insert at least 10 records in each.
Table 1: Supplier (S_No, Sname, Status, City)
Table 2: Parts (P_No, Pname, Color, Weight, City)
Table 3: SP (S_No, P_No, Quantity)
Answer the following queries in SQL:
a) Find the supplier for the city = ‘DELHI’
b) Find the suppliers whose name starts with ‘AB’
c) Find all suppliers whose status is 10, 20 or 30
d) Find total number of cities of all suppliers
e) Find the name of suppliers who supplies quantity of the item P1 more than 50
ANSWER
• Create database dat;
• Use dat;
• create table supplier(s_no int primary key, s_name varchar(20), status int, city varchar(30));
26
27
28
29
1
2.
3.
30
4. Find all suppliers whose status is 10, 20 or 30
Select s_name from supplier where status in (10,20,30);
5. Find the name of suppliers who supplies quantity of the item P1 more than 50
select s_name from supplier, sp where supplier.s_no=sp.s_no and sp.p_no='p1' and sp.quantity>50;
31
Question9: What do you understand by ER Modelling? Explain all the symbols of ER Model with examples.
An entity relationship diagram (ERD), also known as an entity relationship model, is a graphical representation
of an information system that depicts the relationships among people, objects, places, concepts or events within
that system. An ERD is a data modelling technique that can help define business processes and be used as the
foundation for a relational database.
1. Entities, which are objects or concepts that can have data stored about them.
2. Attributes, which are properties or characteristics of entities. An ERD attribute can be denoted as a
primary key, which identifies a unique attribute, or a foreign key, which can be assigned to multiple
attributes.
An entity relationship diagram showing relationships between sales reps, customers and product orders.
For example, an ERD representing the information system for a company's sales department might start with
graphical representations of entities such as the sales representative, the customer, the customer's address, the
customer's order, the product and the warehouse. Then lines or other symbols can be used to represent the
relationship between entities, and text can be used to label the relationships.
A cardinality notation can then define the attributes of the relationship between the entities. Cardinalities can
denote that an entity is optional (for example, a sales rep could have no customers or could have many) or
mandatory (for example, there must be at least one product listed in an order.) The three main cardinalities are:
1. A one-to-one relationship (1:1). For example, if each customer in a database is associated with one
mailing address.
2. A one-to-many relationship (1: M). For example, a single customer might place an order for multiple
products. The customer is associated with multiple entities, but all those entities have a single
connection back to the same customer.
32
33
34
35
36
37
Question10: Draw Entity Relationship diagram of an Organization.
Entity: A definable thins such as person, abject, concept or event that can have data stored about it think of
entities as noun.
In this ERD of organization we have three Entities: - Department, Project, Employee.
Attributes: A property or characteristic of an entity. Often shown as an oval.
Relationship: - Relationships are typically shown as diamonds on the connecting lines. In this ERD of
organization we have four relationships: - works for, supervise, control.
PRIMARY KEY: - The field that is unique for all the record occurrences.it denotes as Underline. In this ERD
we have D_no in as primary key in Department, P_no in Project and Email in Employee.
38
.
39
Question12: Draw Entity Relationship diagram of a Hospital Management System.
Entity: A definable thins such as person, Object, concept or event that can have data stored about it think of
entities as noun.
In this ERD we have five Entities: - Patient, Medical records, Hospital, Doctor, Attributes: A
property or characteristic of an entity. Often shown as an oval.
In this ERD: -
Patient: - P. Name, P.Id, P. Address, P.Diagnosis Hospital: -
Hos.Id, Hos.Name, Hos.No.
Medical records: - R.No, Room. Charge, Doc.Charge
Doctor:-Doc_id, Doc_Name, Salary, Qualification
Relationship: - Relationships are typically shown as diamonds on the connecting lines. In this ERD of
organization we have four relationships: -Has, admitted in, has
PRIMARY KEY: - The field that is unique for all the record occurrences.it denotes as Underline. In this ERD
we have P-id in patient, Hos-id in Hospital, R.No in Medical record, Doc-id in Doctor.
40
Question13: Draw Entity Relationship diagram of a University.
Entity: A definable thins such as person, Object, concept or event that can have data stored about it think of
entities as noun.
In this ERD we have five Entities: - Student, University, College, Course, Faculty Attributes: A
property or characteristic of an entity. Often shown as an oval.
In this ERD:-
Student: - Stu_Id, Stu_Name, DOB, Phone_no
University: - Uni_name, Uni_id, Location, Fees
College: - Name, Location, Clg_id
Course: -Course_Id, Name, Duration
Faculty: -Salary, Fac_name, Fac_id, Qualification
Relationship: - Relationships are typically shown as diamonds on the connecting lines. In this ERD of
organization we have four relationship: -Has, Study in, Enrols in, Teaches by
PRIMARY KEY: - The field that is unique for all the record occurrences.it denotes as Underline. In this
ERD we have Stu_id In Student, Uni_id in University, Clg_id in College, Course_id in Course, Fac_name in
Faculty.
41