Co1 Session 06
Co1 Session 06
TOPIC
SESSION-6
AIM OF THE SESSION
INSTRUCTIONAL OBJECTIVES
This Session is designed to:
Relational Model
Constraints, Schemas
SQL Introduction
LEARNING OUTCOMES
At the end of this session, you should be able to:
•There are minor syntax changes amongst different databases, but the
•basic SQL syntax remains largely the same.
RELATIONAL MODEL
• Relational Model (RM) represents the database as a collection of relations. A relation is
nothing but a table of values. Every row in the table represents a collection of related
data values. These rows in the table denote a real-world entity or relationship.
• The table name and column names are helpful to interpret the meaning of values in
each row. The data are represented as a set of relations. In the relational model, data
are stored as tables. However, the physical storage of the data is independent of the
way the data are logically organized.
BEST PRACTICES FOR CREATING A RELATIONAL MODEL
Data need to be represented as a collection of relations
Each relation should be depicted clearly in the table
Rows should contain data about instances of an entity
Columns must contain data about attributes of the entity
Cells of the table should hold a single value
Each column should be given a unique name
No two rows can be identical
The values of an attribute should be from the same domain
5
RELATIONAL MODEL CONCEPTS
1.Tables – In the Relational model the, relations are saved in the table format. It
is stored along with its entities. A table consists of rows and columns. Rows
represent records and columns represent attributes.
2.Attribute: Each column in a Table are called attribute. Attributes are the
properties which define a relation. e.g., Student_Rollno, NAME,etc.
3.Tuple – It is nothing but a single row of a table, which contains a single record.
4.Relation Schema: A relation schema represents the name of the relation with its
attributes.
5.Degree: The total number of attributes which in the relation is called the degree
of the relation.
6
RELATIONAL MODEL CONCEPTS
8
KEY
A Unique key uniquely identifies each record in the database. This provides uniqueness for the
column or set of columns and it can accept only one null value. Unique key is a subset of
super key.
A primary key is a combination of fields which uniquely specify a row. This is a special kind of
unique key, and it has implicit NOT NULL constraint. It means, Primary key values cannot be NULL.
⚫ A Primary key constraint has automatic unique constraint defined on it. But not, in the case of
Unique Key.
⚫ There can be many unique constraint defined per table, but only one primary key constraint
defined per table.
11
ALTERNATE KEY FOREIGN KEY
12
PRIMARY TABLE & FOREIGN TABLE
Primary table
Foreign Table
Foreign Table
13
SCHEMA DIAGRAM FOR UNIVERSITY DATABASE
Structural Query Language
14
QUERY & SUB-QUERY
A DB query is a code written in order to get the information back from the database.
Query can be designed in such a way that it matched with our expectation of the result set. Simply,
A sub-query is a query within another query. The outer query is called as main query, and inner
Sub-query is always executed first, and the result of sub-query is passed on to the main query.
There are two types of sub-query – Correlated and Non-Correlated.
A correlated sub-query cannot be considered as independent query, but it can refer the
column in a table listed in the FROM the list of the main query.
SQL
Structured Query Language
There are minor syntax changes amongst different databases, but the
basic SQL syntax remains largely the same.
According to ANSI (American National Standards Institute), SQL is the
17
PROCESSING CAPABILITIES OF SQL
3. Embedded SQL
It is a method of combining the computing power of a programming
language and the database manipulation capabilities of SQL.
4.View Definition
The SQL DDL also includes commands for defining views.(Views are the
virtual tables that does not really exist in its own but is derived from one or
more base table(s)).
5.Authorization
The SQL DDL also includes commands for specifying access rights
18 to relation
and views.
PROCESSING CAPABILITIES OF SQL
6.Integrity
The SQL provides limited forms of integrity checking. Future products
and standards of SQL are likely to include enhanced features for
integrity checking.
7.Transaction Control
SQL includes commands for specifying the beginning and
ending of transactions along with the commands to have a
control over transaction processing. 19
DATA DEFINITION LANGUAGE(DDL)
A set of definitions which are expressed by a special language.
An ideal DDL should perform the following functions :
1. Identify the types of data
2. Give a unique name
3. Specify the proper data types
4. Specify how to record types are related to make structures.
5. Define the type of encoding the program uses in the data items.
6. Define the length of data item.
7. Define the range of the values that a data item can assume
8. Specify means of checking for errors in the data.
9. Specify privacy locks.
10. Should not specify addressing, indexing or specify or
searching techniques or specify the storage units.
Data Dictionary
Data dictionary is a file that contains metadata i.e. data
about data.
DATA MANIPULATION LANGUAGE (DML)
24
CONCEPT OF BASIC DATATYPE
Class Data Type
Text CHAR( or, CHARACTER)
Exact Numeric DEC( or, DECIMAL)
NUMERIC
INT(or, INTEGER)
SMALLINT
Organization
for
Standard
JIS Japanese yyyy-mm-dd 2020-03-15 hh-mm-ss 23-13-41
Industrial TIM
Standards E
EUR IBM dd.mm.yyyy 15.03.2020 hh.mm.ss 23.13.41
European
Standard
USA IBM USA mm/dd/yyyy 03/15/2020 hh.mm 11.13 PM
Standard AM/PM
DATE & TIME can be added subtracted or compared
VARIOUS SQL COMMANDS AND FUNCTIONS
1. Keywords : The words that have a special meaning. SQL
keywords have been printed in capital letters.
e.g. NULL, UNIQUE, DEFAULT, CHECK, …etc.
2. Commands or Statements : Instructions to a SQL database
3. Clauses : Commands consist of one or more logically distinct parts
4. Arguments : Modify the meaning of a clause
5. Objects : Structures in the database that are given names and stored
in memory. They include base tables, views & indexes 27
SYMBOLS USED IN SYNTAX OF STATEMENT
Symbols Meaning
| or
{ } treated as a unit
[ ] everything enclosed in it is optional
… repeated any number of times
…. repeated any number of times with the
individual occurrences separated by
commas
< > SQL and other special terms are in
angle brackets 28
RELATIONAL OPERATORS
Symbols Meaning
= equal to
> greater than
< less than
29
ACTIVITIES/ CASE STUDIES/ IMPORTANT FACTS RELATED TO
THE SESSION
(a) Headings
(b) entities
(c) All
(d) None
Ans: a
SELF-ASSESSMENT QUESTIONS
3................................... is the term used in the theory for what is commonly referred to as a column.
(a) Entity
(b) Attributes
(c) Relations
(d) All of the above
ANS: b
TERMINAL QUESTIONS
Reference Books:
1. Database System Concepts, Sixth Edition, Abraham Silberschatz, Yale University Henry, F. Korth
Lehigh University, S. Sudarshan Indian Institute of Technology, Bombay.
2. Fundamentals of Database Systems, 7th Edition, RamezElmasri, University of Texas at Arlington,
Shamkant B. Navathe, University of Texas at Arlington.
Sites and Web links:
3. https://nptel.ac.in/courses/106105175
4. https://beginnersbook.com/2018/11