0% found this document useful (0 votes)
42 views

Unit 2 DBM

This document provides an overview of topics related to the relational data model and SQL. It discusses fundamentals of the relational database management system (RDBMS), E.F. Codd's rules, normalization, keys, data types in SQL, data definition language (DDL) commands, data control language (DCL) commands, data manipulation language (DML) commands, data query language (DQL) commands, and SQL operators. Specific topics covered include database normalization forms, SQL commands for creating, modifying, and deleting tables, data integrity constraints, and using comparison, logical, and set operators in SQL queries.

Uploaded by

AYUSH ATHARE
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)
42 views

Unit 2 DBM

This document provides an overview of topics related to the relational data model and SQL. It discusses fundamentals of the relational database management system (RDBMS), E.F. Codd's rules, normalization, keys, data types in SQL, data definition language (DDL) commands, data control language (DCL) commands, data manipulation language (DML) commands, data query language (DQL) commands, and SQL operators. Specific topics covered include database normalization forms, SQL commands for creating, modifying, and deleting tables, data integrity constraints, and using comparison, logical, and set operators in SQL queries.

Uploaded by

AYUSH ATHARE
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/ 44

Unit 2 Relational data model

• Fundamentals of RDBMS
• Concept of RDBMS
• E.F. Codd's rule
• Key concept
• Normalization
• Introduction to SQL
• Data types in SQL
• DDL commands
Unit 2 Relational data model
• Data integrity constraints
• XML commands
• DCL commands
• DQL (select) command
• SQL operators
Fundamentals of RDBMS
• Concept and definition of RDBMS
• Records
• Field /columns
• Data types
• Table
• Example
Concept of RDBMS
• RDBMS introduction
• DBMS and RDBMS
• Rows and columns
• Relation between two tables
• Keys to form relation
• Some operations on tables
E. F. Codd's rule
• Rule 1- information rule
• Rule 2- guaranteed access rule
• Rule 3 - systematic treatment of null values
• Rule 4 - Active online catalogue
• Rule 5- comprehensive data sub language rule
• Rule 6 - view updating rule
E. F. Codd's rule
• Rule 7 - High level insert, update, delete rule
• Rule 8 - Physical data independence
• Rule 9- Logical data independence
• Rule 10- Integrity independence
• Rule 11-Distribution independence
• Rule 12 - Non subversion rule
Key concept
• Super key

• Candidate key

• Primary key

• Foreign key
Normalization
• Definition- It is process of decomposition of
database to avoid Data redundancy
• Insert anomalies
• Delete anomalies
• Update anomalies
• Functional dependency
First normal form (1NF)
• Concept
• Example
Second Normal Form (2NF)
• Concept
• Non prime attribute-attribute that is not part of any
candidate key is known as non prime attribute.
• Example
Third Normal Form (3NF)
• Concept
• Transitive dependency
• Example
Boyce Codd Normal Form
(BCNF)
• Concept
• Example
Structured Query Language
(SQL)
• SQL-It is a database query language used for storing
and managing data in relational DBMS
• DDL ( Data Definition Language)
• DML (Data Manipulation Language)
• DCL (Data Control Language)
• DQL (Data Query Language)
Data types in SQL
• Char
• Vatcher and varchar 2
• Date
• Number
• Long
• Raw/ Long Raw
DDL commands
• CREATE - to create table
• ALTRR- to modify created table
• DROP - to whole table
• TRUNCATE- to delete rows or records from created
table
• DESC- to see structure of created table
• RENAME- to change name of created table with
new name
• CREATE USER- to create user.
Create table
• Syntax - create table <tablename>
(<columnname1> < datatype>(<size>),
<columnnane2> <datatype>
(<size>),......<columnnamen> <datatype> (<size>);
• E.g.
• create table student ( rollno number (3), name
vatcher (15), mob_no number (10));
• [Note- no spaces between name of column
allowed..you can use underscore ]
Alter table
• Syntax- alter table <tablename> <action to be
taken>;
• E.g. alter table student add address varchar (30);
• Alter table student modify mobile number (11);
• Alter table student delete (address);
Drop table
• Syntax-
• drop table <tablename>;
• E.g drop table student;
• [ Note- This command will delete whole table from
database.. so after execution of this command you
are not able to perform any action on this table, as
it will not exist.]
Truncate command
• Syntax-
• truncate table <tablename>;
• E.g truncate table student;
• Note- using this command only data(contents in
rows) in table table is deleted, table will remain
unchanged.
Desc command
• Syntax-
• desc <tablename>
• E.g. desc student;
• [Used to display current position of table]
Rename table
• Syntax-
• rename <tablename> to <new table name>;
• E.g
• rename student to Student_details;
Create user
• Syntax
• create user <username> identified
externally/globally
• E.g. create user student identified externally;
• [ Note-user can be created with its identity as
externally or globally]
Data integrity constraints
• Concept
• There are two types of data integrity constraints
• 1 I/O constraints
• a) primary key constraints
• b) foreign key constraints
• c) unique key constraints
• 2 Business rule constraints
• a) default constraints
• b) not null constraints
• c). Check constraints
I/ O constraints
• Determines of which data are inserted or extracted
• a) primary key constraints
• Non repeated values
• Not null values in primary ke
• b) foreign key constraints
• Referential integrity constraints or on delete
cascade
• c) unique key constraints
Business rules constraints
• Business rules are used everyday to Define entities
attributes and relationship
• a) default constraints
• b) not null constraints
• Enforces column to not accept null values
• c) check constraints
• Used to avoid entering unnecessary values to the
columns by checking the condition specified
DML commands
• Insert command
• Syntax- insert into <tablename> values (value 1,
value 2,...);
• E.g. insert into student values (01, 'abc',
1234567890, 'naskroad');

DML commands
• UPDATE commands
• Syntax- update <tablename> set
<columnname>=<expression>,
<columnname>=<expression>;
• E.g. update student set name ='xyz' where roll= 02;
DML commands
• DELETE command
• Used to delete records from the table
• Syntax- delete from <tablename> where <
condition>;
• E.g. delete from student where roll=02;
DML commands
• CALL command
• Used to call stored procedure written in SQL
• Syntax-
• CALL <procedure_name>;
• E.g.
• call fact;
• (Fact is stored procedure)
DCL commands
• Used to create rules, permissions, to control access
to database
• Commit- to end transaction and to make effect
permanent to database i.e. to save
• Syntax-
• commit work;
• OR only
• commit
DCL commands
• Savepoint- to temporarily save transactions so that it can
be rolled back to the point where ever required.
• Syntax- savepoint savapoint_name;
• E.g. savepoint S1;
• ( Savepoint_name is user defined)
• Rollback- used to restore the database to last commited
state.It is used with savepoint command
• Syntax- rollback work;
• E.g Rollback; OR
• Rollback S1;
DCL commands
• Grant- to provide access or privilege on database
objects to the users.
• Syntax- grant privilege on <object_name> to
<username>;
• E.g. grant update on student to user 1;
• Revoke- to revoke or remove some or all granted
privileges from database.
• Syntax- revoke privileges on <object_name> from
<username>
• E.g revoke update on student from user 1;
DQL command select
• It includes only one command , select.
• Select command is used to display table rows and
columns in data base.
• Syntax- to show all contents of table
• select * from <table name>;
• E.g. select * from student;
Select with different clauses
• To show perticular rows from a table, select
command is used with where clause
• Syntax-
• select * from <table name> where <condition>;
• E.g. select * from student where rollno= 03;
• Which shows all records of roll no= 03.
• In space of * different column names can also be
placed, to display perticular value of a column
specified.
SQL Operators
• Operators represents actions.
• Three types of operators
• 1 Arithmetic operators
• 2 comparison operators
• 3 Logical operators
Arithmetic operators
• Used for arithmetic operations as addition,
subtraction, multiplication, division
• Select Empid, empname, salary+incentive from
empdetails;
• (Create empdetails tables and add some values
first)
Comparison operator
• Used mostly to compare attribute values
• E.g. select Empid, empname, address from
empdetails where salary >10000;
Logical operator
• Used when one or more conditions should be true
• Three logical operator AND, OR, NOT
• E.g select * from empdetails where salary>10000
ÀND salary< 30000;
• Select Empid, empname from empdetails where
address=Nasik OR address= Mumbai;
• Select Empid, empname from empdetails where
address NOT like 'pune';
Set operators
• To combine output of two queries the special type
of operators used known as set operators.
• Union operator
• It selects distinct values of same attribute of
different related table.
• E. g. Select Empid from empdetails Union select
Empid from deptdetails;
Set operators
• Union all-
• It combines all records from both the queries
without avoiding duplicate values
• E g. select Empid from empdetails Union all select
empid from deptdetails;
Set operators
• Intersect
• It is used to find out similar attribute values between
two tables for same attribute
• E. G. Select Empid from empdetails Intersect select
Empid from deptdetails;
• Minus
• It is subtraction operator. The difference between two
columns are expressed using minus operator.
• E. G. Select Empid from empdetails minus select Empid
from deptdetails;
Range searching operator
• Between
• To search value between a particular range,
BETWEEN operator is used.
• E. G. Select Empid from deptdetails where deptno
between 1 and 4;
Pattern matching operators
• Like
• It is used pattern matching of ssc string. It is used
with NOT logical operator.
• Special characters are used to match pattern of
string
• "? "- used to match single character
• " %"- used to match number of characters
• E. G. Select Empid, empname from empdetails
where empname like ‘%esh' ;
Thank you

You might also like