0% found this document useful (0 votes)
21 views46 pages

DMA-chapter No1

The document discusses concepts related to relational databases and SQL. It covers topics like relational model concepts including tables, attributes, tuples, relations schema, cardinality, keys. It also discusses relational algebra operations and SQL data types and languages like DDL, DML, DCL.

Uploaded by

Kiran Kshirsagar
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)
21 views46 pages

DMA-chapter No1

The document discusses concepts related to relational databases and SQL. It covers topics like relational model concepts including tables, attributes, tuples, relations schema, cardinality, keys. It also discusses relational algebra operations and SQL data types and languages like DDL, DML, DCL.

Uploaded by

Kiran Kshirsagar
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/ 46

Amrutvahini Polytechnic Sangamner

Program – IF Class – IF4I

Course – Database Management Code – 22416

Staff – Navale N.D


Database Management
• Theory
• ESE – 70 Marks
• PA – 30 Marks (Test1+Test2 and Microproject)

• Practical
• ESE – 50 M
• PA – 50 M
Chapter No 1
Creating Relational Database(08 M)

1. Relational Database Design

2. RDBMS Technology

3. Introduction to SQL
Concepts of relational database
• The relational data model was introduced by E. F. Codd
in 1970.
• it is the most widely used data model.
• The relational data model describes the world as “a
collection of inter-related relations (or tables).” A
relational data model involves the use of data tables
that collect groups of elements into relations.
• These models work based on the idea that each table
setup will include a primary key or identifier. Other
tables use that identifier to provide "relational" data
links and results.
Relational Model Concepts
Terms
• Attribute: Each column in a Table. Attributes are the properties which
define a relation. e.g., Student_Rollno, NAME,etc.

• Tables – In the Relational model the, relations are saved in the table
format. It is stored along with its entities. A table has two properties rows
and columns. Rows represent records and columns represent attributes.

• Tuple – It is nothing but a single row of a table, which contains a single


record.

• Relation Schema: A relation schema represents the name of the relation


with its attributes.

• Column: The column represents the set of values for a specific attribute.
Cardinality

• Cardinality refers to the relationship between


two tables
One-to-One
• When only one tuple in relation is related with only
one tuple in another relation , then it is known as
one to one cardinatity.
• For example, one Department have one Manager
One-to-many
• When only one tuple in relation is related with Many
tuple in another relation , then it is known as one to
many cardinatity.
• For example, Scientist can invent many inventions,
but the invention is done by the only specific
scientist.
Many-to-one
• When more than one tuple in relation is related with
only one tuple in another relation , then it is known
as Many to one cardinatity.

• For example, Student enrolls for only one course, but


a course can have many students.
Many-to-many relationship
• When more than one tuple in relation is related with
Many tuple in another relation , then it is known as
many to many cardinatity.

• For example, Employee can assign by many projects


and project can have many employees.
Keys

• It is used to uniquely identify any record or


row of data from the table.
Primary key

• It is the first key which is used to identify one and only one
instance of an entity uniquely.

• In the EMPLOYEE table, ID can be primary key since it is


unique for each employee.

• In the EMPLOYEE table, ID can be primary key since it is


unique for each employee. In the EMPLOYEE table, we can
even select License_Number and Passport_Number as
primary key since they are also unique.
Candidate key

• A candidate key is an attribute or set of an attribute which


can uniquely identify a tuple.

• The remaining attributes except for primary key are


considered as a candidate key. The candidate keys are as
strong as the primary key.

• In the EMPLOYEE table, id is best suited for the primary


key. Rest of the attributes like SSN, Passport_Number, and
License_Number, etc. are considered as a candidate key.
Super Key

• Super key is a set of an attribute which can uniquely identify a


row.
• Super key is a minimal subset of a candidate key from which no
subset can be created.

• For example: In the above EMPLOYEE table, for(EMPLOEE_ID,


EMPLOYEE_NAME) the name of two employees can be the
same, but their EMPLYEE_ID can't be the same. Hence, this
combination can also be a key.

• The super key would be EMPLOYEE-ID, (EMPLOYEE_ID,


EMPLOYEE-NAME), etc.
Foreign key

• Foreign keys are the attribute of the table which is used to point to the
primary key of another table.

• In a company, every employee works in a specific department, and


employee and department are two different entities. So we can't store
the information of the department in the employee table. That's why
we link these two tables through the primary key of one table.

• We add the primary key of the DEPARTMENT table, Department_Id as a


new attribute in the EMPLOYEE table.

• Now in the EMPLOYEE table, Department_Id is the foreign key, and both
the tables are related.
DBMS Software
Relational Algebra

• Relational algebra is a procedural query


language, which takes instances of relations as
input and yields instances of relations as
output.
• It uses operators to perform queries.
• An operator can be either unary or binary.
Operations of relational algebra
• Select
• Project
• Union
• Set different
• Cartesian product
• Rename
Select Operation (σ)

• It selects tuples/rows that satisfy the given


condition from a relation/table.
• Notation − σp(r)
• Where σ stands for selection predicate
and r stands for relation. p is prepositional
logic formula which may use connectors
like and, or, and not. These terms may use
relational operators like − =, ≠, ≥, < , >, ≤.
For example −
• σsubject = "database"(Books) Output − Selects tuples
from books where subject is 'database'.
• σsubject = "database" and price = "450"(Books) Output − Selects
tuples from books where subject is 'database'
and 'price' is 450.
• σsubject = "database" and price = "450" or year > "2010"(Books)
Output − Selects tuples from books where
subject is 'database' and 'price' is 450 or those
books published after 2010.
Project Operation (∏)

• It projects/selects column(s) that satisfy a


given condition.
• Notation − ∏A1, A2, An (r)
• Where A1, A2 , An are attribute names of
relation r.
• Duplicate rows are automatically eliminated,
as relation is a set.
For example −
• ∏subject, author (Books) Selects and projects
columns named as subject and author from
the relation Books.
Union Operation (∪)

• It performs binary union between two given relations and is


defined as −
• r ∪ s = { t | t ∈ r or t ∈ s} Notation − r U s
• Where r and s are either database relations or relation result set
(temporary relation).
• For a union operation to be valid, the following conditions must
hold −
• r, and s must have the same number of attributes.
• Attribute domains must be compatible.
• Duplicate tuples are automatically eliminated.
• ∏ author (Books) ∪ ∏ author (Articles) Output − Projects the names of
the authors who have either written a book or an article or both.
Set Difference (−)

• he result of set difference operation is tuples,


which are present in one relation but are not in
the second relation.
• Notation − r − s
• Finds all the tuples that are present in r but not
in s.
• ∏ author (Books) − ∏ author (Articles) Output −
Provides the name of authors who have written
books but not articles.
Cartesian Product (Χ)

• Combines information of two different relations


into one.
• Notation − r Χ s
• Where r and s are relations and their output will
be defined as −
• r Χ s = { q t | q ∈ r and t ∈ s}
• σauthor = 'tutorialspoint'(Books Χ Articles) Output − Yields
a relation, which shows all the books and
articles written by tutorialspoint.
Rename Operation (ρ)

• The results of relational algebra are also relations but


without any name. The rename operation allows us to
rename the output relation. 'rename' operation is
denoted with small Greek letter rho ρ.
• Notation − ρ x (E)
• Where the result of expression E is saved with name of x.
• Additional operations are −
• Set intersection
• Assignment
• Natural join
SQL
SQL Data types
DDL-Data Definition Language
• DDL or Data Definition Language actually consists of the SQL
commands that can be used to define the database schema. It
simply deals with descriptions of the database schema and is used
to create and modify the structure of database objects in the
database.Examples of DDL commands:
• CREATE – is used to create the database or its objects (like table,
index, function, views, store procedure and triggers).
• DROP – is used to delete objects from the database.
• ALTER-is used to alter 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.
DML(Data Manipulation Language)
• The SQL commands that deals with the
manipulation of data present in the database
belong to DML or Data Manipulation Language and
this includes most of the SQL statements.Examples
of DML:
• INSERT – is used to insert data into a table.
• UPDATE – is used to update existing data within a
table.
• DELETE – is used to delete records from a database
table.
DCL(Data Control Language)
• DCL includes commands such as GRANT and
REVOKE which mainly deals with the rights,
permissions and other controls of the
database system.Examples of DCL commands:
• GRANT-gives user’s access privileges to
database.
• REVOKE-withdraw user’s access privileges
given by using the GRANT command.
TCL(transaction Control Language)
• TCL commands deals with the
transaction within the database. Examples of TCL
commands:
• COMMIT– commits a Transaction.
• ROLLBACK– rollbacks a transaction in case of any
error occurs.
• SAVEPOINT–sets a savepoint within a transaction.
• SET TRANSACTION–specify characteristics for the
transaction.
DDL
• CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype,
....
);
• Create table student(roll number(2),name
char(5));
ALTER TABLE

• The ALTER TABLE statement is used to add,


delete, or modify columns in an existing table.

• ALTER TABLE - ADD Column


• ALTER TABLE table_name
ADD column_name datatype;
• ALTER TABLE Customers
ADD Email varchar(255);
• ALTER TABLE - DROP COLUMN
• ALTER TABLE table_name
DROP COLUMN column_name;
• ALTER TABLE Customers
DROP Email;
DROP TABLE

• DROP TABLE table_name;

• DROP TABLE customer;


rename
• Rename table <old_table name> to
<new_table name>

• Rename customer to customer_data;


Drop
• Drop table table_name;

• Drop table customer;


Truncate
• Truncate table table_name;

• Truncate table customer;

You might also like