0% found this document useful (0 votes)
8 views45 pages

DBM Chapter1

It is helpful Op fjfjfjw djfjfjwkf

Uploaded by

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

DBM Chapter1

It is helpful Op fjfjfjw djfjfjwkf

Uploaded by

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

Database Management System(22416)

Unit 1 : Creating Relational Database


(08 Marks)

Presented By :
Mrs. Samidha Chavan
Lecturer -Department of Information Tech.
Vidyalankar Polytechnic, Wadala (Mumbai)
Unit 1 : Creating Relational Database

1. Relational Database Design


2. RDBMS Terminology .
3. Introduction to SQL .
1.2 RDBMS Terminology
Table : Student
Rollno Name
1 Sita
2 Gita
3 Nita

1. Tuple - In Relational Model, row is called “Tuple”.


For example : Tuple 1 Sita

The above table have 3 Tuples.


1.2 RDBMS Terminology
Table : Student
Rollno Name
1 Sita
2 Gita
3 Nita

2. Attribute - Column Header is called Attribute .


For example : Student table has two attributes Rollno
and Name .

3. Degree of table – Number of attributes of table is


called “Degree of table”
For Example : Degree of Student Table = 2
1.2 RDBMS Terminology
Table : Student
Rollno Name
1 Sita
2 Gita
3 Nita

4. Domain - All permissible values are called Domain


For Example : Domain of Rollno are 1,2,3
Domain of Name are Sita , Gita, Nita .

5. Cardinality – Number of rows in a table is called Cardinality


For Example : Cardinality of Student Table = 3
1.1 Relational Database Design

• Relational database design (RDD) models


information and data into a set of tables with rows and
columns.

• Each row of a relation/table represents a record, and


each column represents an attribute of data.

• The Structured Query Language (SQL) is used to


manipulate relational databases

Roll no Name Marks


11 Sita 80
Relation( Table )- STUDENT 12 Gita 85
13 Nita 90
Types of Relational Database Software (RDBMS software)

• MariaDB
• Db2
• SQLite
• Oracle Database XE
• Sequel Pro
• PostgreSQL
• SQL Server Express
• MySQL
Different Relational Algebra Operators

Relational algebra is a procedural query language. It gives a


step by step process to obtain the result of the query. It
uses operators to perform queries.
Different Relational Algebra Operators
Different Relational Algebra Operators
Different Relational Algebra Operators
Different Relational Algebra Operators
Different Relational Algebra Operators
Different Relational Algebra Operators
Different Relational Algebra Operators
Different Relational Algebra Operators
Different Relational Algebra Operators
Different Relational Algebra Operators
Different Relational Algebra Operators
1.3 Structured Query Language
What is SQL?
• SQL stands for Structured Query Language
• SQL lets you access and manipulate databases
Structured Query Language
What Can SQL do?
• SQL can execute queries against a database
• SQL can retrieve data from a database
• SQL can insert records in a database
• SQL can update records in a database
• SQL can delete records from a database
Structured Query Language
Data types in SQL:
➢ CHAR(size)
➢ VARCHAR(size)/VARCHAR2(SIZE)
➢ Numeric/NUMBER(P,S)- Integer, Float, Decimal etc
➢ DATE

➢ For Example :
Percentage NUMBER(5,2) ;
It can store max value 999.99
Structured Query Language
Components of SQL:
Data Definition Language
Data Definition Language:
• DDL commands modify the actual structure of a database,
rather than the database’s contents.

• DDL Commands includes:


1. create Student
2. alter
3. drop
4. truncate
5. desc/describe
6. rename
Data Definition Language
CREATE:
It is used to create a new table in the database.

Syntax :

CREATE TABLE TABLE_NAME (


COLUMN1 DATATYPE,
COLUMN2 DATATYPE,
COLUMN3 DATATYPE,
....
);
Data Definition Language

Syntax : Example:

CREATE TABLE TABLE_NAME ( CREATE TABLE EMPLOYEE(


COLUMN1 DATATYPE, NAME VARCHAR2(100),
COLUMN2 DATATYPE,
EMAIL VARCHAR2(50),
COLUMN3 DATATYPE,
.... AGE NUMBER(3)
); );
Data Definition Language
ALTER:
• It is used to alter the structure of the database.
• This change could be either to modify the
characteristics of an existing attribute or probably to
add a new attribute.

EMPLOYEE
NAME(VARCHAR2(100)) EMAIL(VARCHAR2(50)) AGE(NUMBER(3))
Data Definition Language
To add a new column in the table

Syntax : Example:

ALTER TABLE TABLE_NAME ALTER TABLE EMPLOYEE


ADD COLUMN_NAME ADD CITY VARCHAR2(50);
DATATYPE;

EMPLOYEE
NAME(VARCHAR2(100)) EMAIL(VARCHAR2(50)) AGE(NUMBER(3)) CITY(VARCHAR2(50))
Data Definition Language
To modify column in the table
Syntax : Example:

ALTER TABLE TABLE_NAME


MODIFY ALTER TABLE EMPLOYEE
COLUMN_NAME MODIFY
NEW_DATATYPE; CITY VARCHAR2(80);

Modified Structure of EMPLOYEES TABLE


NAME(VARCHAR2(100)) EMAIL(VARCHAR2(50)) AGE(NUMBER(3)) CITY(VARCHAR2(80))
Data Definition Language
DROP:
It is used to delete both the structure and record stored
in the table.

Syntax :

DROP TABLE TABLE_NAME ;

Example:

DROP TABLE EMPLOYEE;


Data Definition Language
TRUNCATE:
It is used to delete all the rows from the table and free
the space containing the table.
Syntax :

TRUNCATE TABLE table_name;

Example:

TRUNCATE TABLE EMPLOYEE;


Types of Integrity Constraints ( 1 mark )
Integrity Constraints ( 1 mark )

Integrity constraints are divided into Domain, Entity and


Referential.
• Domain constraints has Not Null constraint, CHECK
constraint.
• Entity constraints has Primary Key Constraints,
Unique Key constraints
• Referential constraints has Foreign Key Constraints
Entity Integrity Constraint ( 1 mark )

Entity integrity constraint ensure that there are no duplicate


records within the table.

Entity Integrity Constraint are of two types:


1. Primary Key
2. Unique Key
Primary Key Constraint ( 2 mark )

• Primary Key uniquely identify each row in the table.


• Primary Key avoid duplication of rows.
• Primary Key do not allow null values.

For Example : Employee table

Primary Key

Empid Ename Salary Phone


How to set Primary Key Constraint ?

For example :

create table employee


(
Empid number(3) primary key,
Ename varchar(10),
Salary number(7,2),
Phone number(10)
);
Unique Key Constraint ( 2 mark )

• Unique Key avoid duplication of values in a columns.


• Column defined with Unique key also allow null values.

For Example : Employee table

Unique Key

Empid Ename Salary Phone


How to set Unique key Constraint ?

For example :

create table employee


(
Empid number(3) ,
Ename varchar(10),
Salary number(7,2),
Phone number(10) unique
);
Domain Integrity Constraints ( 2 mark )

It is used to maintain value according to user specification.

Domain Integrity Constraint are of two types:


1. Not null constraint
2. Check constraint
Not null Constraint ( 2 mark )

• It is applied on a column to avoid null values.

For Example : Apply not null constraint on Ename column

create table employee


(
Empid number(3) ,
Ename varchar(10) not null,
Salary number(7,2),
Phone number(10)
);
Check Constraint ( 2 mark )

• It define a condition that each row must satisfy .

For Example : Apply check constraint on Salary column

create table employee


(
Empid number(3) ,
Ename varchar(10),
Salary number(7,2) check (salary >=5000),
Phone number(10)
);
Referential Integrity Constraints
Foreign Key
A Foreign key is a primary key from one table and appears as a
field in another table.

For example :
For Student Relation ,
Foreign Key : {Course_id}
Foreign Key Parent Table
Child Table
Table 1 : Student Table 2 : Course
RollNo Name Course_id Course_id Course_Name

1 Sita CO1 CO1 Computer

2 Gita IF2 IF2 Information Tech

3 Nita EJ3 EJ3 Electronics


How to set Foreign Key Constraint ?

For example :

create table student


(
Rollno number(3) primary key,
Name varchar(10),
Course_id varchar(3),
FOREIGN KEY(Course_id) REFERENCES Course(Course_id)
);
What is on DELETE cascade ?

if a record in the parent table is deleted, then the


corresponding records in the child table will automatically be
deleted. This is called a On delete cascade
How to set Foreign Key Constraint with on delete
cascade ?

For example :

create table student


(
Rollno number(3) primary key,
Name varchar(10),
Course_id varchar(3),
FOREIGN KEY(Course_id) REFERENCES Course(Course_id) on delete cascade
);

You might also like