Ism Lab File
Ism Lab File
Undertaken at
1
lOMoARcPSD|32628230
Date:
Signature of the Faculty Guide
Name
2
lOMoARcPSD|32628230
Acknowledgement
Roll No-
07127401721
3
lOMoARcPSD|32628230
VISION
MISSION
4
lOMoARcPSD|32628230
INDEX
1 Introduction to SQL 3- 6
2 EXPLAIN SQL DDL COMMANDS 7-8
3 EXPLAIN SQL DML COMMANDS 9-11
4 Primary Key Constraint & Foreign Key Constraint 12-13
5 Update Command & Alter Command 14
6 ‘Order By’ and ‘Like’ Clause 15-16
7 Aggregate Functions 17-19
8 Command for operators 20-22
9 Command for and, or, not operators 22-23
10 Command for indexes and view 24
11 Command for Upper case. Lower case, Substring, Replace 25-26
15 Create the supplier and parts tables and perform SQL 34-36
commands
16 ER Model 37
17 Explain all the symbols of ER Model 38-42
18 Entity Relationship diagram of an Organization 43
19 Entity Relationship diagram of a Banking System 44
20 Entity Relationship diagram of a Hospital 45
21 Entity Relationship diagram of a University 46
5
lOMoARcPSD|32628230
SQL Data Types define the type of value that can be stored in a table
column. For example, if we want a column to store only integer values,
then we can define its data type as .
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.
6
lOMoARcPSD|32628230
• Not all data types are supported by every relational database vendor. For
example, Oracle database doesn’t support DATETIME and MySQL doesn’t
support CLOB data type. So while designing database schema and writing SQL
queries, make sure to check if the data types are supported or not.
• Data typeslisted here doesn’t include all the data types, these are the
most popularly used data types. Some relational database vendors
have their own data types that might be not listed here. For example,
Microsoft SQL Server has and data types but since it’snot
supported by other popular database vendors, it’s not listed here.
• Every relational database vendor has its own maximum size limit for different
data types, you don’t need to remember the limit. Idea is to have the knowledge
of what data type to be used in a specific scenario.
bit 0 1
tinyint 0 255
7
lOMoARcPSD|32628230
8
lOMoARcPSD|32628230
Note that all the above data types are for character stream, they should
not be used with Unicode data.
Note that above data types are not supported in MySQL database.
9
lOMoARcPSD|32628230
10
lOMoARcPSD|32628230
Ques 2:- EXPLAIN SQL DDL COMMANDS. With Syntax and Examples.
• CREATE: This command is used to create the database or its objects (like
table, index, function, views, store procedure, and triggers).
SYNTAX
11
lOMoARcPSD|32628230
•
SYNTAX
ALTER TABLE table_name
ADD column_name datatype;
12
lOMoARcPSD|32628230
1. SELECT Command
2. INSERT Command
3. UPDATE Command
4. DELETE Command
SYNTAX
FROM table_name;
13
lOMoARcPSD|32628230
SYNTAX
14
lOMoARcPSD|32628230
SYNTAX
UPDATE table_name
SET column1 = value1, column2 = value2...., columnN = valueN WHERE
[condition];
15
lOMoARcPSD|32628230
SYNTAX
DELETE FROM table_name WHERE condition;
16
lOMoARcPSD|32628230
Ques 4:- Write a command for Primary Key Constraint & Foreign
Key Constraint PRIMARY KEY
A primary key is the column or columns that contain values that
uniquely identify each row in a table. A database table must have a
primary key for Optim to insert, update, restore, or delete data from a
database table. Optim uses primary keys that are defined to the
database. However, you can also define primary keys to supplement
those in the database.
SYNTAX
FOREIGN KEY
The FOREIGN KEY constraint is used to prevent actions that would destroy
links between tables.
17
lOMoARcPSD|32628230
A FOREIGN KEY is a field (or collection of fields) in one table, that refers
to the PRIMARY KEY in another table.
The table with the foreign key is called the child table, and the table with
the primary key is called the referenced or parent table.
SYNTAX
CREATE TABLE orders (O_Id int NOT NULL, Order_No int NOT NULL, S
_Id int, PRIMAY KEY (O_Id), FOREIGN KEY (S_Id) REFERENCES
Persons ( S_Id)) ;
18
lOMoARcPSD|32628230
Ques 5:- Write a command for Update Command & Alter Command
UPDATE
SYNTAX
UPDATE table_name
SYNTAX
ALTER TABLE table_name
ADD column_name datatype;
19
lOMoARcPSD|32628230
ORDER BY Syntax
20
lOMoARcPSD|32628230
The LIKE operator is used in a WHERE clause to search for a specified pattern in
a column.
There are two wildcards often used in conjunction with the LIKE operator:
LIKE Syntax
21
lOMoARcPSD|32628230
22
lOMoARcPSD|32628230
1. COUNT FUNCTION
23
lOMoARcPSD|32628230
Syntax
2. SUM Function
Sum function is used to calculate the sum of all selected columns. It works on
numeric fields only.
Syntax
3. AVG function
Syntax
24
lOMoARcPSD|32628230
4. MAX Function
MAX function is used to find the maximum value of a certain column. This
function determines the largest value of all selected values of a column.
Syntax
5. MIN Function
MIN function is used to find the minimum value of a certain column. This
function determines the smallest value of all selected values of a column.
Syntax
25
lOMoARcPSD|32628230
26
lOMoARcPSD|32628230
LESS THAN
GREATER THAN
27
lOMoARcPSD|32628230
BETWEEN
LIKE
28
lOMoARcPSD|32628230
IN
29
lOMoARcPSD|32628230
NOT
OR
30
lOMoARcPSD|32628230
Indexes are used to retrieve data from the database more quickly than
otherwise. The users cannot see the indexes, they are just used to speed
up searches/queries.
A view contains rows and columns, just like a real table. The fields
in a view are fields from one or more real tables in the database.
You can add SQL statements and functions to a view and present the data
as if the data were coming from one single table.
31
lOMoARcPSD|32628230
32
lOMoARcPSD|32628230
Ques 11:- Write a command for Upper case. Lower case, Substring, Replace
UPPER ():
This function in SQL Server helps to convert all the letters of the
given string to Uppercase. If the given string contains special
characters or numeric values, then they will remain unchanged by
this function. Syntax :
LOWER ():
SYNTAX
SUBSTRING :
33
lOMoARcPSD|32628230
REPLACE:
34
lOMoARcPSD|32628230
35
lOMoARcPSD|32628230
CONCAT
Syntax
LENGTH
LENGTH(string)
36
lOMoARcPSD|32628230
37
lOMoARcPSD|32628230
• INSERT 10 RECORDS
38
lOMoARcPSD|32628230
39
lOMoARcPSD|32628230
40
lOMoARcPSD|32628230
Ques 14:- Create the following table and perform sql commands
student (roll_no, name, age, course, marks).
• Select student name where age is greater than 18 & course is equal
to MBA
41
lOMoARcPSD|32628230
• Find out name, course, marks from student order by marks asc.
42
lOMoARcPSD|32628230
43
lOMoARcPSD|32628230
Ques 15:- Create the following tables. Insert atleast 10 records in each.
a) Supplier (s_no, sname, status, city)
44
lOMoARcPSD|32628230
45
lOMoARcPSD|32628230
46
lOMoARcPSD|32628230
47
lOMoARcPSD|32628230
This is the highest level ER model in that it contains the least granular
detail but establishes the overall scope of what is to be included within the
model set. The conceptual ER model normally defines master reference
data entities that are commonly used by the organization. Developing an
enterprise-wide conceptual ER model is useful to support documenting the
data architecture for an organization.
48
lOMoARcPSD|32628230
A conceptual ER model may be used as the foundation for one or more logical
data models (see below). The purpose of the conceptual ER model is
then to establish structural metadata commonality for the master data
entities between the set of logical ER models. The conceptual data model may
be used to form commonality relationships between ER models as a basis for
data model integration.
A physical data model specifies how the data model will be built in the database. It
outlines all table structures, including column name, data types, column constraints,
primary key and foreign key with indexes to the relevant table column, relationships
between tables, stored procedures, and views.
The responsibility regarding physical data model creation usually lies with
database administrators and developers. Information systems and software
applications heavily rely on interactions with physical databases. Physical data
models need to be designed and implemented correctly. It is challenging to
modify physical data models once data from the existing application has been
inserted into databases.
49
Entity Symbol Name Description
lOMoARcPSD|32628230
50
lOMoARcPSD|32628230
Entities are objects or concepts that represent important data. Entities are
typically nouns such as product, customer, location, or promotion. There
are three types of entities commonly used in entity relationship diagrams.
Examples of entities:
51
lOMoARcPSD|32628230
Relationships are
Relationship associations between or
among entities.
ERD attributes are characteristics of the entity that help users to better
understand the database. Attributes are included to include details of the
various entities that are highlighted in a conceptual ER diagram.
52
lOMoARcPSD|32628230
Cardinality
Defines the numerical attributes of the relationship between two entities or entity
sets.
• One-to-One Relationships
• One-to-Many Relationships
• Many-to-Many Relationships
53
lOMoARcPSD|32628230
1. One-to-one:
One entity from entity set X can be associated with at most one entity
of entity set Y and vice versa.
Example: One student can register for numerous courses. However, all
those courses have a single line back to that one student.
2. One-to-many:
54
lOMoARcPSD|32628230
One entity from entity set X can be associated with multiple entities of
entity set Y, but an entity from entity set Y can be associated with at
least one entity.
3. Many to One
More than one entity from entity set X can be associated with at most
one entity of entity set Y. However, an entity from entity set Y may or
may not be associated with more than one entity from entity set X.
4. Many to Many:
One entity from X can be associated with more than one entity from Y and vice
versa.
55
lOMoARcPSD|32628230
56
lOMoARcPSD|32628230
-
Ques 18: Draw Entity Relationship diagram of an Organization.
57
lOMoARcPSD|32628230
Management System.
58
lOMoARcPSD|32628230
59