KEMBAR78
DBMS Notes: DDL DML DCL | PPTX
B.Tech III Sem ‘A’
DATABASE MANAGEMENT
SYSTEMS
Topics Covered
 Database users
 Database Architecture
 DDL
 DML
Student
Std_ID Name
Addr
Sec
DoB
Std_ID Name Addr Sec DoB
189X1A05XY Sree Sanfransisco A 01/01/1999
189X1A05XZ Sri Germany B+ 01/01/2000
ER Model Relational Model
ER Model Vs. Relational Model
Naive / Prgmers / Sophisticated / DBA
Appl.
interface
s
Appl.
programs
Query
tools
Admin
tools
Query Processor
Object
code
Compiler
DML
Queries
DDL
Interpreter
Query Evaluation Engine
Storage Manager
Buffer
Manager
File
Manager
Authorization &
integrity manager
Transaction
Manager
Data Indice
s
Data
Dictionar
y
Disk Storage
Users
DDL Commands
DDL:
Data Definition
Language
 CREATE
 ALTER
 DROP
 RENAME
DML:
Data Manipulation Language
 INSERT
 UPDATE
 DELETE
 SELECT
DCL:
Data Control Language
 GRANT
 REVOKE
 COMMIT (TCL)
 ROLLBACK (TCL)
DDL: Create
CREATE TABLE
CUSTOMER1(
ID Number(2),
NAME NVARCHAR2 (20),
AGE INT,
ADDRESS NVARCHAR2
(30) ,
SALARY DECIMAL (10, 2)
create table cust_temp as
select id, name from
customer1;
CREATE TABLE STUDENT2
(
ID INT NOT NULL,
NAME VARCHAR(20) NOT
NULL,
AGE INT NOT NULL,
DDL: Alter
 ALTER TABLE table_name ADD column_name
datatype;
 ALTER TABLE table_name DROP COLUMN
column_name;
 ALTER TABLE table_name MODIFY COLUMN
column_name datatype;
 ALTER TABLE table_name MODIFY column_name
datatype NOT NULL;
DDL Command: DROP &
Rename
 Drop table student;
 Rename student1 to student2;
 TRUNCATE TABLE customer1;
DML: Data Manipulation Language
 INSERT
 UPDATE
 DELETE
 SELECT
DML Example: Insert
insert into customer1values(90, 'Codd',60,'San Fransisco',
150000);
insert into customer1 values(&id,
'&name',&age,'&address',&salary);
SELECT * FROM EMPLOYEE
UPDATE Customer1 set ID=18, WHERE Name='henry
korth';DELETE FROM Customer1 WHERE Name='Henry Korth' AND
age=60;
Today’s Topics
 DCL
 Entity Relationship Model
 Basic concepts
 Cardinality of Relationship
 ER Diagram Notations
 ER Diagrams: Examples
DCL: Data Control Language
 GRANT : used to grant or give the privileges.
 REVOKE : used to avoid or object the privileges.
 COMMIT: used to save the data permanently.
 ROLL BACK : Used to revert changes in the
transactions since the last commit or rollback
command was issued
DCL: Commit
DELETE FROM
CUSTOMERS
WHERE AGE = 25;
SQL> COMMIT;
Rollback
 ROLLBACK command is the transactional
command used to undo transactions that have
not already been saved to the database.
 This command can only be used to undo
transactions since the last COMMIT or
ROLLBACK command was issued.
 DELETE FROM CUSTOMERS WHERE AGE =
25;
DCL : Grant & Revoke
create user korth identified by henry
 Connect as system/ora10g
GRANT SELECT, INSERT, UPDATE, DELETE
ON Emp_Det TO korth;
REVOKE DELETE ON Emp_details FROM
Entity Relationship Model
 The ER data model facilitates database design
by allowing specification of an enterprise
schema that represents the overall logical
structure of a database.
 The E-R data model employs three basic
concepts: entity sets, relationship sets, and
attributes
Entity Sets
 Entity: Real-world object distinguishable from other
objects. An entity is described (in DB) using a
set of attributes.
 Entity Set: A collection of similar entities. E.g., all
employees.
 All entities in an entity set have the same set of attributes.
 Each entity set has a key.
 Each attribute has a domain.
Entity Sets
Relationship Sets
 Relationship: Association among two or more
entities.
 A relationship set is a mathematical relation
among n  2 entities, each taken from entity sets
{(e1, e2, … en) | e1  E1, e2  E2, …, en 
En}
where (e1, e2, …, en) is a relationship
Relationship: Depositor
Relationship: Borrower
Attributes
 An entity is represented by a set of
attributes, that is descriptive properties
possessed by all members of an entity
set.Example:
customer = (customer_id, customer_name, customer_street,
customer_city )
loan = (loan_number, amount )
Attribute types
 Simple : Attribute is simple, if its value can not be divided into subparts.
For example Std_ID, GPA.
 Composite : Attribute is composite, if its value can be divided into
subparts. Ex: Name: First Name; Middle Name; Last Name
Address: H.No; street; city; pincode
 Single-valued : Attribute is a single-valued, if it has only one value for a
particular entity
 Multivalued : Attribute is multivalued, if it has a set of values for a
particular entity. Ex: Phone number
 Derived: Attribute is a derived, if its value can be derived from the values
of other related attributes or entities. Ex: Age, given dateofbirth
ER Diagram Notations
 Rectangles represent entity sets
 Ellipses represent attributes
 Diamonds represent relationship sets
 Lines link attributes to entity sets and link entity
sets to relationships sets
Continued…
 ER Diagram Notations
 ER Diagram Examples

DBMS Notes: DDL DML DCL

  • 1.
    B.Tech III Sem‘A’ DATABASE MANAGEMENT SYSTEMS
  • 2.
    Topics Covered  Databaseusers  Database Architecture  DDL  DML
  • 3.
    Student Std_ID Name Addr Sec DoB Std_ID NameAddr Sec DoB 189X1A05XY Sree Sanfransisco A 01/01/1999 189X1A05XZ Sri Germany B+ 01/01/2000 ER Model Relational Model ER Model Vs. Relational Model
  • 4.
    Naive / Prgmers/ Sophisticated / DBA Appl. interface s Appl. programs Query tools Admin tools Query Processor Object code Compiler DML Queries DDL Interpreter Query Evaluation Engine Storage Manager Buffer Manager File Manager Authorization & integrity manager Transaction Manager Data Indice s Data Dictionar y Disk Storage Users
  • 5.
    DDL Commands DDL: Data Definition Language CREATE  ALTER  DROP  RENAME DML: Data Manipulation Language  INSERT  UPDATE  DELETE  SELECT DCL: Data Control Language  GRANT  REVOKE  COMMIT (TCL)  ROLLBACK (TCL)
  • 6.
    DDL: Create CREATE TABLE CUSTOMER1( IDNumber(2), NAME NVARCHAR2 (20), AGE INT, ADDRESS NVARCHAR2 (30) , SALARY DECIMAL (10, 2) create table cust_temp as select id, name from customer1; CREATE TABLE STUDENT2 ( ID INT NOT NULL, NAME VARCHAR(20) NOT NULL, AGE INT NOT NULL,
  • 7.
    DDL: Alter  ALTERTABLE table_name ADD column_name datatype;  ALTER TABLE table_name DROP COLUMN column_name;  ALTER TABLE table_name MODIFY COLUMN column_name datatype;  ALTER TABLE table_name MODIFY column_name datatype NOT NULL;
  • 8.
    DDL Command: DROP& Rename  Drop table student;  Rename student1 to student2;  TRUNCATE TABLE customer1;
  • 9.
    DML: Data ManipulationLanguage  INSERT  UPDATE  DELETE  SELECT
  • 10.
    DML Example: Insert insertinto customer1values(90, 'Codd',60,'San Fransisco', 150000); insert into customer1 values(&id, '&name',&age,'&address',&salary); SELECT * FROM EMPLOYEE UPDATE Customer1 set ID=18, WHERE Name='henry korth';DELETE FROM Customer1 WHERE Name='Henry Korth' AND age=60;
  • 11.
    Today’s Topics  DCL Entity Relationship Model  Basic concepts  Cardinality of Relationship  ER Diagram Notations  ER Diagrams: Examples
  • 12.
    DCL: Data ControlLanguage  GRANT : used to grant or give the privileges.  REVOKE : used to avoid or object the privileges.  COMMIT: used to save the data permanently.  ROLL BACK : Used to revert changes in the transactions since the last commit or rollback command was issued
  • 13.
  • 14.
    Rollback  ROLLBACK commandis the transactional command used to undo transactions that have not already been saved to the database.  This command can only be used to undo transactions since the last COMMIT or ROLLBACK command was issued.  DELETE FROM CUSTOMERS WHERE AGE = 25;
  • 15.
    DCL : Grant& Revoke create user korth identified by henry  Connect as system/ora10g GRANT SELECT, INSERT, UPDATE, DELETE ON Emp_Det TO korth; REVOKE DELETE ON Emp_details FROM
  • 16.
    Entity Relationship Model The ER data model facilitates database design by allowing specification of an enterprise schema that represents the overall logical structure of a database.  The E-R data model employs three basic concepts: entity sets, relationship sets, and attributes
  • 17.
    Entity Sets  Entity:Real-world object distinguishable from other objects. An entity is described (in DB) using a set of attributes.  Entity Set: A collection of similar entities. E.g., all employees.  All entities in an entity set have the same set of attributes.  Each entity set has a key.  Each attribute has a domain.
  • 18.
  • 19.
    Relationship Sets  Relationship:Association among two or more entities.  A relationship set is a mathematical relation among n  2 entities, each taken from entity sets {(e1, e2, … en) | e1  E1, e2  E2, …, en  En} where (e1, e2, …, en) is a relationship
  • 20.
  • 21.
  • 22.
    Attributes  An entityis represented by a set of attributes, that is descriptive properties possessed by all members of an entity set.Example: customer = (customer_id, customer_name, customer_street, customer_city ) loan = (loan_number, amount )
  • 23.
    Attribute types  Simple: Attribute is simple, if its value can not be divided into subparts. For example Std_ID, GPA.  Composite : Attribute is composite, if its value can be divided into subparts. Ex: Name: First Name; Middle Name; Last Name Address: H.No; street; city; pincode  Single-valued : Attribute is a single-valued, if it has only one value for a particular entity  Multivalued : Attribute is multivalued, if it has a set of values for a particular entity. Ex: Phone number  Derived: Attribute is a derived, if its value can be derived from the values of other related attributes or entities. Ex: Age, given dateofbirth
  • 25.
    ER Diagram Notations Rectangles represent entity sets  Ellipses represent attributes  Diamonds represent relationship sets  Lines link attributes to entity sets and link entity sets to relationships sets
  • 26.
    Continued…  ER DiagramNotations  ER Diagram Examples