0% found this document useful (0 votes)
17 views35 pages

Co1 Session 06

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

Co1 Session 06

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

DEPARTMENT OF CSE

DATA BASE MANAGEMENT SYSTEMS


22CS2110 RA

TOPIC

RELATIONAL MODEL ,SQL INTRODUCTION

SESSION-6
AIM OF THE SESSION

To familiarize students with the basic concept

 ER to Relatational Model, SQL Introduction

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:

 Know the conversion of ER to Relational Model


 Know the DBMS Constraints, Schemas
 Introduction of SQL.
SESSION INTRODUCTION

DBMS – 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.
SQL Introduction
 SQL is a language which is used to create & operatedatabase.
 SQL is the basic language used for all the databases.

 SQL can be used by both casual users as well as skilled programmer.

•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

6. Cardinality: Total number of rows present in the Table.


7. Column: The column represents the set of values for a specific attribute.
8. Relation instance – Relation instance is a finite set of tuples in the RDBMS system.
Relation instances never have duplicate tuples.

9. Relation key - Every row has one, two or multiple attributes,


• which is called relation key.
10. Attribute domain – Every attribute has some pre-defined value and scope which
is known as attribute domain
TABLE

8
KEY

A DBMS Key is an attribute or set of attributes which helps us to identify a


row (tuple) in a relation(table). It allows us to find the relation between two
tables.
There are different types of keys:
1. Super Key
2. Unique Key
3. Primary Key
4. Candidate Key
5. Alternate Key
6. Foreign Key
SUPER KEY CANDIDATE KEY & NON-PRIME ATTRIBUTE
 Super Key: A super key is a set of one or more attributes(columns), which can uniquely
identify a row in a table.
 Candidate Key: A super key with no redundant attribute is known as candidate key.
 Non-prime Attribute: An attribute that is not part of any candidate key is known as non-
prime attribute. Emp_Id Emp_Number Emp_Name
E01 2264 Steve
E02 2278 John
E03 2288 Martin
E04 2297 Robert
Super Key: Candidate Key:
1.
2.
{Emp_Id}
{Emp_Number}
1. {Emp_Id}
3. {Emp_Id} {Emp_Number} 2. {Emp_Number}
4. {Emp_Number} {Emp_Name}
5. {Emp_Id} {Emp_Name} Non-prime attribute
6. {Emp_Id} {Emp_Number} {Emp_Name} {Emp_Name} 10
UNIQUE KEY & PRIMARY 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.

⚫ Primary Key can be chosen from Candidate key.

⚫ There can be many unique constraint defined per table, but only one primary key constraint
defined per table.
11
ALTERNATE KEY FOREIGN KEY

A candidate key, that is not a primary key is called anAlternate key.


A non key attribute(or a group of non-key attributes) whose values are
derived from primary key of some other table is known as Foreign
key in its current table.
 Foreign key is used to represent the relationship between two
tables.
Foreign key of a table is a primary key of some other table.

12
PRIMARY TABLE & FOREIGN TABLE

 The table in which foreign key attribute exists, is called a


Foreign Table or Detail table.
 The table that defines the primary key, which is the foreign key of the detail
table or Foreign table refers to, is called Primary table or Master table.
Primary key

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 question to the Database.

A sub-query is a query within another query. The outer query is called as main query, and inner

query is called sub-query.

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

 SQL is a language which is used to create & operate database.


 SQL is the basic language used for all the databases.
 SQL can be used by both casual users as well as skilled programmer.

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

standard language to operate a relational database management system.


SQL is used in the accessing, updating, and manipulation of data in a
database. Its design allows for the management of data in an RDBMS, such as
MYSQL and PostgreSQL.
16
PROCESSING CAPABILITIES OF SQL

1. DATA DEFINITION LANGUAGE(DDL)


The SQL DDL provides commands for defining relation schemas,
deleting relations, creating indexes and modifying relation schemas .

2.INTERACTIVE DATA MANIPULATION LANGUAGE(DML)

The SQL DML includes a query language based on both relational


algebra and the tuple relational calculus. It includes the commands
to insert, delete and modify tuples in the data base.

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)

Data manipulation language (DML) is a language that enables


users to access or manipulate data as organized by the appropriate
data model.
By data manipulation we mean
1.Retrieval
2.Insertion
3.Deletion
4.Modification
TYPES OF DATA MANIPULATION LANGUAGE(DML)

DML’s are Basically of two types


1)Procedural DML
It requires a user to specify what data is needed and how to
get it.
2) Non-procedural DML
It requires a user to specify what data is needed without
specifying how to get it. 23
SQL PROCESSING

SQL is a language oriented specifically around relational


databases.
The SQL command can operate on entire groups of tables
as a single object and can treat any quantity of information
extracted or derived from them as a single unit as well.

24
CONCEPT OF BASIC DATATYPE
Class Data Type
Text CHAR( or, CHARACTER)
Exact Numeric DEC( or, DECIMAL)
NUMERIC
INT(or, INTEGER)
SMALLINT

Approximate Numeric FLOAT


REAL
DOUBLE(or, DOUBLE
PRECISION)
Date & Time
Currency
25
DATE & TIME
Date Time
Standard Full Form Format Example Format Example
ISO International yyyy-mm-dd 2020-03-15 hh-mm-ss 23-13-41

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

>= greater equal to

<= less equal to

<> not equal to

29
ACTIVITIES/ CASE STUDIES/ IMPORTANT FACTS RELATED TO
THE SESSION

The relational model in DBMS is an abstract model used to organize and


manage the data stored in a database. It stores data in two-dimensional
inter-related tables, also known as relations in which each row represents
an entity and each column represents the properties of the entity.
SQL stands for Structured Query Language. It is used for storing and
managing data in relational database management system (RDMS).It is a
standard language for Relational Database System. It enables a user to
create, read, update and delete relational databases and tables.
All the RDBMS like MySQL, Informix, Oracle, MS Access and SQL
Server use SQL as their standard database language.
SUMMARY

The relation, which is a two-dimensional table, is the primary unit of storage


in a relational database.
A relational database can contain one or more of these tables, with each table
consisting of unique set of rows and columns.
A single record is stored in a table as a row, also known as a tuple, while
attributes of the data are defined in columns or fields in the table.
Each column has a unique name and the content within it must be of the same
type.
The characteristics of the data, or the column, relates one record to another.
SELF-ASSESSMENT QUESTIONS

1. .........................................first formulated and proposed in 1969 by Edgar Codd.

(a) Relational model


(b) DBMS model
(c) Virtual Model
(d) Data Model
Ans: a

2. A................................... is a set of attributes..

(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

1.Describe the relational model concept of DBMS.


2. What do you mean by alternatives to the relational model?
3. Describe NULL concept in database.
4 Describe various data types in SQL.
5. List out the DBMS languages and explain the use of the
languages.
REFERENCES FOR FURTHER LEARNING OF THE SESSION

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

You might also like