0% found this document useful (0 votes)
142 views133 pages

DMS (22319) - Chapter 2 Notes

The document discusses key concepts in relational databases including tables, records, fields, columns, keys like candidate keys, primary keys and foreign keys. It also explains Codd's 12 rules for relational database management systems.

Uploaded by

pdijgqam1n
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)
142 views133 pages

DMS (22319) - Chapter 2 Notes

The document discusses key concepts in relational databases including tables, records, fields, columns, keys like candidate keys, primary keys and foreign keys. It also explains Codd's 12 rules for relational database management systems.

Uploaded by

pdijgqam1n
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/ 133

Unit-II:

RELATIONAL DATA MODEL


[ 18 Marks]

Mr. S. Y. Divekar

Database Management System (DMS)


Database Management System (DMS) Mr. S. Y. Divekar
Lecture :- 1 : Outlines
Fundamentals / concept of RDBMS,
Table
Record
Field
Column

Database Management System (DMS) Mr. S. Y. Divekar


Fundamentals of RDBMS
Relational Database Management systems:
RDMS:
The advanced version of DBMS is known as RDBMS.
The relational data model was introduced by C. F. Codd in
1970. Currently, it is the most widely used data model.
“The database which stores data in the tables that have
relationships with other tables in the database is called
RDBMS or Relational Database Management System.”
Name of RDBMS software: Oracle, My SQL, SQL Server,
DB2

Database Management System (DMS) Mr. S. Y. Divekar


RDBMS:
A Relational Database management System(RDBMS) is a
database management system based on the relational model
introduced by E.F Codd. In relational model, data is stored
in relations(tables) and is represented in form of tuples(rows).
Data storage capacity is very high.
In a relational database, all data is held in tables, which are made
up of rows and columns.
Each table has one or more columns, and each column is assigned
a specific datatype, such as an integer number, a sequence of
characters (for text), or a date. Each row in the table has a value
for each column.

Database Management System (DMS) Mr. S. Y. Divekar


Table:
In Relational database, a table is a collection of data elements
organized in terms of rows and columns.
A table is also considered as convenient representation of
relations. But a table can have duplicate tuples while a true
relation cannot have duplicate tuples. Table is the most simplest
form of data storage.
Below is an example of Employee table.

ID Name Age Salary


1001 Krishna 25 20000
1002 Sanchi 30 35000
1003 Aastha 21 25000
1004 Gargi 32 36000

Database Management System (DMS) Mr. S. Y. Divekar


Record :
A single entry in a table is called a Record or Row. A Record in a
table represents set of related data.
For example, the above Employee table has 4 records. Following
is an example of single record.
ID Name Age Salary
1001 Krishna 25 20000
1002 Sanchi 30 35000
1003 Aastha 36 25000
1004 Gargi 32 36000

ID Name Age Salary


1001 Krishna 25 20000

Database Management System (DMS) Mr. S. Y. Divekar


Field :
A table consists of several records(row), each record can be
broken into several smaller entities known as Fields.
The above Employee table consist of four fields, ID, Name, Age
and Salary.
ID Name Age Salary
1001 Krishna 25 20000
1002 Sanchi 30 35000
1003 Aastha 36 25000
1004 Gargi 32 36000

ID Name Age Salary

Database Management System (DMS) Mr. S. Y. Divekar


Column :
In Relational table, a column is a set of value of a particular type.
The term Attribute is also used to represent a column.
For example, in Employee table, Name is a column that represent
names of employee.

ID Name Age Salary Name


1001 Krishna 25 20000 Krishna
1002 Sanchi 30 35000 Sanchi
1003 Aastha 36 25000 Aastha
1004 Gargi 32 36000 Gargi

Database Management System (DMS) Mr. S. Y. Divekar


Lecture :- 2 : Outlines
E.F. Codd’s Rule for RDBMS,

Database Management System (DMS) Mr. S. Y. Divekar


The Codd's 12 rules:
Codd's Rule E.F Codd was a Computer Scientist who invented
Relational model for Database management.
The Codd's 12 rules to test DBMS's concept against his relational
model.
Codd's rule actually define what quality a DBMS requires in order
to become a Relational Database Management System(RDBMS).

Database Management System (DMS) Mr. S. Y. Divekar


The Codd's 12 rules are as follows:
Rule zero This rule states that for a system to qualify as an RDBMS, it
must be able to manage database entirely through the relational
capabilities.
Rule 1 : Information rule
All information(including metadata) is to be represented as stored data
in cells of tables. The rows and columns have to be strictly unordered.
Rule 2 : Guaranteed Access
Each unique piece of data(atomic value) should be accessible by : Table
Name + primary key(Row) + Attribute(column).
NOTE : Ability to directly access via POINTER is a violation of this rule.
Rule 3 : Systematic treatment of NULL
Null has several meanings, it can mean missing data, not applicable or
no value. It should be handled consistently. Primary key must not be
null. Expression on NULL must give null.
Database Management System (DMS) Mr. S. Y. Divekar
Rule 4 : Active Online Catalog
Database dictionary( catalog ) must have description of Database.
Catalog to be governed by same rule as rest of the database. The same
query language to be used on catalog as on application database.
Rule 5 : Powerful language
One well defined language must be there to provide all manners of
access to data.
Example: SQL. If a file supporting table can be accessed by any manner
except SQL interface, then its a violation to this rule.
Rule 6 : View Updating rule
All view that are theoretically updatable should be updatable by the
system.

Database Management System (DMS) Mr. S. Y. Divekar


Rule 7 : Relational Level Operation
There must be Insert, Delete, Update operations at each level of relations. Set
operation like Union, Intersection and minus should also be supported.
Rule 8 : Physical Data Independence
The physical storage of data should not matter to the system. If say,
some file supporting table were renamed or moved from one disk to
another, it should not effect the application.
Rule 9 : Logical Data Independence
If there is change in the logical structure(table structures) of the
database the user view of data should not change. Say, if a table is split
into two tables, a new view should give result as the join of the two
tables. This rule is most difficult to satisfy.

Database Management System (DMS) Mr. S. Y. Divekar


Rule 10 : Integrity Independence
The database should be able to conformed its own integrity rather than
using other programs. Key and Check constraints, trigger etc. should be
stored in Data Dictionary. This also make RDBMS independent of front-
end.
Rule 11 : Distribution Independence
A database should work properly regardless of its distribution across a
network. This lays foundation of distributed database.
Rule 12 : No subversion rule
If low level access is allowed to a system it should not be able to
subvert or bypass integrity rule to change data. This can be achieved
by some sort of looking or encryption.

Database Management System (DMS) Mr. S. Y. Divekar


Lecture :- 3 : Outlines
 Key Concepts-
Candidate key,
Primary key,
Foreign key.

Database Management System (DMS) Mr. S. Y. Divekar


Keys:
Keys play an important role in the relational database.
It is used to uniquely identify any record or row of data from the
table.
It is also used to establish and identify relationships between
tables.
For example:
In Student table, Roll No. is
used as a key because it is
unique for each student.
In PERSON table,
passport_number,
license_number, SSN are keys
since they are unique for each
person.

Database Management System (DMS) Mr. S. Y. Divekar


Types of Keys:
DBMS has Five types of Keys in it and they all has different
functionality.
The Keys are as follows:
◦ • Super Key
◦ • Candidate Key
◦ • Primary Key
◦ • Foreign Key
◦ • Composite Key

Database Management System (DMS) Mr. S. Y. Divekar


Super Keys:
- A super key is a group of single or multiple keys which identifies
rows in a table.
“Super key is a set of an attribute which can uniquely identify a
tuple. “
Super key is a superset of a candidate key.

For example:
In the 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…

Database Management System (DMS) Mr. S. Y. Divekar


Candidate Keys:
“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.
A subset of a super key.
Candidate Key is a super key with no repeated attributes.
The Primary key should be selected from the candidate keys.
Every table must have at least a single candidate key. A table can
have multiple candidate keys but only a single primary key.

Mr. S. Y. Divekar
Properties of Candidate Keys:
It must contain unique values
Candidate key may have multiple attributes
Must not contain null values
It should contain minimum fields to ensure uniqueness
Uniquely identify each record in a table

For example: 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.

Database Management System (DMS) Mr. S. Y. Divekar


Primary Keys:
“Primary Keys is a column or group of columns in a table that
uniquely identify every row in that table. “
It is the first key which is used to identify one and only one
instance of an entity uniquely.
The Primary Key can't be a duplicate meaning the same value
can't appear more than once in the table.
A table cannot have more than one primary key.
For each entity, selection of the primary key is based on
requirement and developers.

Database Management System (DMS) Mr. S. Y. Divekar


Rules for defining Primary key:
Unique values (Two rows can't have the same value)
Uniquely identify each record in the table.
The primary key field cannot be null.
The value in a primary key column can never be modified or
updated if any foreign key refers to that primary key.
For example: 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.

Database Management System (DMS) Mr. S. Y. Divekar


Foreign Keys:
“The relationship between two tables matches the Primary Key
in one of the tables with a Foreign Key in the second table. “
A FOREIGN KEY is a key used to link or relationship of two tables
together. This is sometimes also called as a referencing key.
A FOREIGN KEY is a field (or collection of fields) in one table that
refers to the PRIMARY KEY in another table.
The table containing the foreign key is called the child table, and
the table containing the candidate key is called the referenced or
parent table.
Rules for defining Primary key:
Foreign key columns must use their referenced column's type.
A foreign key column cannot be a computed column.
Foreign key columns must be indexed.
Database Management System (DMS) Mr. S. Y. Divekar
For example: 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.

Database Management System (DMS) Mr. S. Y. Divekar


Composite Keys:
“When a primary key is created from a combination of two or
more columns, the primary key is called a composite key. “
Composite Key is a combination of two or more columns that
uniquely identify rows in a table. The combination of columns
guarantees uniqueness, though individually uniqueness is not
guaranteed.
Hence, they are combined to uniquely identify records in a table.
A composite key consists of more than one field to uniquely
identify a record.

Database Management System (DMS) Mr. S. Y. Divekar


For example: Consider a table with three attitudes customer ID, product ID,
product quantity
Customer ID needs to be entered for each time the customer purchases an
order hence customer ID appears more than once in the customer ID table
hence it cannot be served as the primary key i.e it failed to uniquely identify
a record
Example customer ID 66 has placed two orders hence customer ID appeared
66 two times in the customer ID column
Product ID and product quality cannot be
declared as the primary key because of more
than one customer purchase same product and
the same quantity
In this situation all three attributes fail to
serve as a primary key .Hence combination of
these attribute can be used as a primary key
For example [customer ID, product ID] can be
used as the primary key table customers this
combination helps to uniquely access records of
customer

Database Management System (DMS) Mr. S. Y. Divekar


Lecture :- 4 / 5 : Outlines
 Normalization Concepts,
 Needs of Normalization.
Types of Normalization-1NF, 2NF,3NF.

Database Management System (DMS) Mr. S. Y. Divekar


Normalization:
“Normalization is a process of efficiently organizing the data in
database to avoid data redundancy, insertion anomaly, update
anomaly & deletion anomaly.”
OR
“Normalization is the process of minimizing redundancy from a
relation or set of relations.”
A process of organizing data into tables in such a way that the
results of using the database are always unambiguous and as
intended. Such normalization is intrinsic to relational database
theory. It may have the effect of duplicating data within the
database and often results in the creation of additional tables.

Database Management System (DMS) Mr. S. Y. Divekar


Reasons for Normalization or Need for
Normalization:
Insertion anomalies: If the user fails to insert information
about a new database entry into all the places in the database
where information about that new entry needs to be stored.
Deletion anomalies: If the user fails to remove information
about an existing data when it is time to remove that data.
Updating anomalies : An update of a database involves
modifications of data all the places in the database where
information about that new entry needs to be stored..

Database Management System (DMS) Mr. S. Y. Divekar


Levels of Normalization:
Levels of normalization based on the amount of redundancy
in the database.
Various levels of normalization are:
◦ First Normal Form (1NF)
◦ Second Normal Form (2NF)
◦ Third Normal Form (3NF)
◦ Boyce - Codd Normal Form (BCNF)
◦ Fourth Normal Form (4NF)
◦ Fifth Normal Form (5NF)
◦ Domain Key Normal Form (DKNF) OR (6NF)

Database Management System (DMS) Mr. S. Y. Divekar


Steps in Normalization:

Redundancy

Number of Tables

Complexity
Database Management System (DMS) Mr. S. Y. Divekar
First Normal Form:
“A table is said to be in First Normal Form (1NF) if and only if
each attribute of the relation is atomic. ”
OR
“A relation R is said to be in first normal form (1NF) if the
domain of all attributes of R are atomic.”
That is,
Each row in a table should be identified by primary key (a unique column
value or group of unique column values)
No rows of data should have repeating group of column values.
First Normal Form (1NF) enforces these criteria:
Eliminate repeating groups in individual tables.
Create a separate table for each set of related data.
Identify each set of related data with a primary key

Database Management System (DMS) Mr. S. Y. Divekar


First Normal Form:
For Example: Student(Surname, Name, Knowledge)
The attribute Knowledge can contain multiple values and
therefore the relation is not in the first normal form.
But the attributes Name and Surname are atomic attributes that
can contain only one value.
To get to the first normal form (1NF)
we must create a separate tuple
for each value of the multivalued
attribute

Database Management System (DMS) Mr. S. Y. Divekar


Second Normal Form:
“A relation is in second normal form if it is in 1NF and every non
key attribute is fully functionally dependent on the primary key.

That is,
A relation is in 2NF if it has No Partial Dependency, i.e., no non-
prime attribute (attributes which are not part of any candidate
key) is dependent on any proper subset of any candidate key of
the table.
Partial Dependency – If the proper subset of candidate key
determines non-prime attribute, it is called partial dependency.

Database Management System (DMS) Mr. S. Y. Divekar


Second Normal Form:
For Example: Student(IDSt, StudentName, IDProf, ProfessorName, Grade)
The attributes IDSt and IDProf are the identification keys.
All attributes a single valued (1NF).
The following functional dependencies exist:
1. The attribute ProfessorName is
functionally dependent on attribute
IDProf (IDProf --> ProfessorName)
2. The attribute StudentName is
functionally dependent on
IDSt (IDSt --> StudentName)
3. The attribute Grade is
fully functional dependent on
IDSt and IDProf (IDSt, IDProf --> Grade)

Database Management System (DMS) Mr. S. Y. Divekar


Third Normal Form:
“A relation is in third normal form, if there is no transitive
dependency for non-prime attributes as well as it is in second
normal form. ”
That is,
It is in second normal form
There is no transitive functional dependency(To achieve 3NF,
eliminate the Transitive Dependency.)
Transitive functional dependency, we mean we have the
following relationships in the table: A is functionally dependent
on B, and B is functionally dependent on C. In this case, C is
transitively dependent on A via B.

Database Management System (DMS) Mr. S. Y. Divekar


Third Normal Form:
For Example: In the table able, [Book ID] determines [Genre ID], and [Genre
ID] determines [Genre Type]. Therefore, [Book ID] determines [Genre Type]
via [Genre ID] and we have transitive functional dependency, and this
structure does not satisfy third normal form.
To bring this table to third normal form,
we split the table into two as follows:

Now all non-key attributes are fully


functional dependent only on the primary
key.
In [TABLE_BOOK], both [Genre ID]
and [Price] are only dependent on
[Book ID]. In [TABLE_GENRE],
[Genre Type] is only dependent
on [Genre ID].

Database Management System (DMS) Mr. S. Y. Divekar


Boyce-Codd Normal Form:
“A relationship is said to be in BCNF if it is already in 3NF and
the left hand side of every dependency is a candidate key. ”
BCNF is the advance version of 3NF. It is stricter than 3NF.
That is,
It should be in the Third Normal Form.
And, for any dependency A → B, A should be a super key.

Database Management System (DMS) Mr. S. Y. Divekar


Boyce-Codd Normal Form:
For Example: Consider, as an example,
1. A professor can work in more than one department
2. The percentage of the time he spends in each
department is given.
3. Each department has only one Head of Department.
The relation diagram for the above relation is
given as the following:
The given relation is in 3NF. Observe, however,
that the names of Dept. and Head of Dept. are
duplicated.
Further, if Professor P2 resigns, rows 3 and 4
are deleted.
We lose the information that Rao is the Head
of Department of Chemistry.

Database Management System (DMS) Mr. S. Y. Divekar


Boyce-Codd Normal Form:
The normalization of the relation is done by creating a new relation
for Dept. and Head of Dept. and deleting Head of Dept. form the
given relation.
The normalized relations are shown in the following.

See the dependency diagrams for these new relations.

Database Management System (DMS) Mr. S. Y. Divekar


Fourth Normal Form:
“A relation will be in 4NF if it is in Boyce Codd normal form and
has no multi-valued dependency. ”
“A table is said to have multi-valued dependency, if the following
conditions are true.”
It should be in the Boyce-Codd Normal Form.
the table should not have any Multi-valued Dependency.
Multi-valued Dependency, Multivalued dependency occurs when
two attributes in a table are independent of each other but, both
depend on a third attribute.
A multivalued dependency consists of at least two attributes that
are dependent on a third attribute that's why it always requires at
least three attributes.

Database Management System (DMS) Mr. S. Y. Divekar


Fourth Normal Form:
For Example: consider a table with Subject, Lecturer who teaches each
subject and recommended Books for each subject.

If we observe the data in the table above it satisfies 3NF. But LECTURER and
BOOKS are two independent entities here.
There is no relationship between Lecturer and Books. In the above example,
either Alex or Bosco can teach Mathematics. For Mathematics subject , student
can refer either ‘Maths Book1’ or ‘Maths Book2’.
i.e.:
SUBJECT –> LECTURER
SUBJECT–>BOOKS

Database Management System (DMS) Mr. S. Y. Divekar


Fourth Normal Form:
This is a multivalued dependency on SUBJECT. If we need to select both lecturer
and books recommended for any of the subject, it will show up (lecturer, books)
combination, which implies lecturer who recommends which book.
This is not correct.
To eliminate this dependency, we divide the table into two as below:

Hence it removes the multi-valued dependency and confusion around the data.
Thus the table is in 4NF.
Database Management System (DMS) Mr. S. Y. Divekar
Fifth Normal Form:
“A relation is in Fifth Normal Form (5NF), if it is in 4NF, and
won’t have lossless decomposition into smaller tables.. ”
The 5NF (Fifth Normal Form) is also known as project-join normal
form.
A relation is in 5NF if it is in 4NF and not contains any join
dependency and joining should be lossless.
5NF is satisfied when all the tables are broken into as many
tables as possible in order to avoid redundancy.

Database Management System (DMS) Mr. S. Y. Divekar


Fifth Normal Form:
Join Dependency:
If a table can be recreated by joining multiple tables and each of
this table have a subset of the attributes of the table, then the
table is in Join Dependency. It is a generalization of Multivalued
Dependency
For Example: consider a table, John takes both Computer and Math class for
Semester 1 but he doesn't take Math class for Semester 2. In this case,
combination of all these fields required to identify a valid data.

Database Management System (DMS) Mr. S. Y. Divekar


Fifth Normal Form:
Suppose we add a new Semester as Semester 3 but do not know about the
subject and who will be taking that subject so we leave Lecturer and Subject as
NULL. But all three columns together acts as a primary key, so we can't leave
other two columns blank.
So to make the above table into 5NF, we can decompose it into three relations
P1, P2 & P3:

Database Management System (DMS) Mr. S. Y. Divekar


Lecture :- 6 : Outlines
 Introduction to Structure Query Language,
Data Types in SQL.

Database Management System (DMS) Mr. S. Y. Divekar


Structure Query Language:
“SQL is Structured Query Language, which is a computer
language for storing, manipulating and retrieving data stored in
relational database. .”
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.

Database Management System (DMS) Mr. S. Y. Divekar


SQL Data Types:
a. char
b. varchar or varchar2
c. number
d. date
e. long
f. long raw/ raw

Database Management System (DMS) Mr. S. Y. Divekar


Char(n) :
This data type is used to store character strings of fixed size.
The size of the character string is determined by the numeric
value of n.
This data type can hold maximum of 255 characters. When
Oracle stores data in a CHAR data type, it will pad the value
stored in the column up to the length of the column as declared
by the table with blanks.
For example: If data type of address field is mentioned as
CHAR(40) and address information of a particular record
complete in 20 characters, then remaining 20 characters space is
padded with blank characters.

Database Management System (DMS) Mr. S. Y. Divekar


Varchar(n) / Varchar2(n) :
This data type is used to store variable length alphanumeric
data.
It can store maximum of 2000 characters. In case of varchar data
type, Oracle will not store padded blank spaces if the value
stored in a column defined is less than length of the column as
declared by the table with data type VARCHAR2.
For example: If data type of address field is mentioned as
VARCHAR(40) and address information of a particular record
complete in 20 characters, then remaining 20 characters space is
not padded with blank characters and memory space of 20
characters is used for some other purposes and not wasted as
padded with blank characters.

Database Management System (DMS) Mr. S. Y. Divekar


Number (p,s) :
This data type is used to store numbers fixed or floating point .
The precision (p) determines the length of the data while the
scale (s), determines the number of places after the decimal.
The NUMBER data type that is used to store number data can be
specified either to store integers or decimals with the addition of
a parenthetical precision indicator.
For example: if you had a column defined to be data type
NUMBER(10,3), the number 546.3832 would be stored as
546.383, because after the decimal point we can store 3 digits. It
can store a number of 10 digits including a decimal point for
example a maximum number of 999999.999 can be stored with
data type of NUMBER(10,3).

Database Management System (DMS) Mr. S. Y. Divekar


Date:
This data type, stores date values in a special format internal to
Oracle.
It offers a great deal of flexibility to users who want to perform
date manipulation operations There are also numerous functions
that handle date operations more complex than simple
arithmetic.
The default format in which date is stored is DD-MON-YY. If we
want to store date in other format then we have to use the
appropriate functions.

Database Management System (DMS) Mr. S. Y. Divekar


Long:
The developer can declare columns to be of LONG data type,
which can stores upto 2 gigabytes of alphanumeric text data.
The values of long data type cannot be indexed and normal
characters functions such as SUBSTR cannot be applied to long
values.
Long Raw / Raw:
It is useful to store graphics and sound files when used in
conjunction with LONG to form the LONG RAW data type, which
can accommodate up to 2 gigabytes of data.
Note: A table cannot contain more than one Long column. They
cannot be indexed and no integrity constraints can be applied on
them (except for NULL and NOT NULL constrain).

Database Management System (DMS) Mr. S. Y. Divekar


Data Types:

Database Management System (DMS) Mr. S. Y. Divekar


Lecture :- 7 : Outlines
 SQL Fundamentals

Database Management System (DMS) Mr. S. Y. Divekar


SQL Fundamentals:
Structured Query Language is a simple and powerful language
used to create, access, and manipulate data and structure in the
database.
SQL is like plain English: easy to understand and to write.
SQL statements into various categories, which are:
•Data Definition Language
•Data Manipulation Language
•Data Control Language.
•Transaction Control Language
•Embedded SQL statements

Database Management System (DMS) Mr. S. Y. Divekar


Data Definition Language (DDL) statements:
DDL statements are used to define, alter, or drop database
objects. The following table gives an overview about usage of
DDL statements in ORACLE (a commercially used database):

Database Management System (DMS) Mr. S. Y. Divekar


Data Manipulation Language (DML) statements:
Once the tables have been created, the DML statements enable
users to query or manipulate data in existing schemas objects.
DML statements are normally the most frequently used
commands.
The following table gives an overview about the usage of DML
statements in ORACLE.

Database Management System (DMS) Mr. S. Y. Divekar


Data Control Language (DCL):
A privilege can either be granted to a User with the help of
GRANT statement.
The privileges assigned can be SELECT, ALTER, DELETE, EXECUTE,
INSERT, INDEX etc.
In addition to granting of privileges, you can also revoke it by
using REVOKE command.

Database Management System (DMS) Mr. S. Y. Divekar


Transaction Control Statements (TCL):
TCL statements manage the change made by DML statements,
and group DML statements into transactions.
The following table gives an overview about the usage of TCL
statements in ORACLE.

Database Management System (DMS) Mr. S. Y. Divekar


Embedded SQL statements:
The SQL statements used to incorporate DDL,DML and
transaction control statements within the body of a procedural
language program, are known as Embedded SQL statements.
The following table gives an overview about the usage of
Embedded SQL statements in ORACLE.

Database Management System (DMS) Mr. S. Y. Divekar


Structured Query Language Commands:

Database Management System (DMS) Mr. S. Y. Divekar


Lecture :- 2.5 : Outlines
Fundamentals SQL
DDL Commands

Database Management System (DMS) Mr. S. Y. Divekar


Data Definition Language (DDL) :
The functions of the DDL are:
1. DDL defines the physical characteristics of each record, filed in
the record, fields data type, fields length, fields logical name and
also specify relationship among those records.

2. DDL describes the schema and subschema.

3. DDL indicate the keys of records.

4. DDL provides data security measures.

5. DDL provides for the logical and physical data independence.

Database Management System (DMS) Mr. S. Y. Divekar


DDL Commands:
Create command:
A Create table command is used to create table in a database.
Syntax: Example:
Create table table_name CREATE TABLE Student
(column_name1 datatype(size), (Roll_no number(4),
column_name2 datatype(size), Name char(30),
…… DOB date,
column_nameN datatype(size)); Address varchar2(50));

Database Management System (DMS) Mr. S. Y. Divekar


DESC command:
The table structure can be described by using Describe command.
Syntax:
DESC table_name;
Example:
Desc student;

Database Management System (DMS) Mr. S. Y. Divekar


ALTER Table Command:
The use of ALTER TABLE Command we can modify our exiting
table.
Adding New Columns
Syntax:
ALTER TABLE table_name
ADD (NewColumnName Data_Type(size),......n);
Example:
ALTER TABLE Student ADD (Age number(2), Marks number(3));
The Student table is already exist and then we added two more
columns Age and Marks respectively, by the use of above
command.

Database Management System (DMS) Mr. S. Y. Divekar


ALTER Table Command:
Dropping a Column from the Table
Syntax:
ALTER TABLE table_name DROP COLUMN column_name;
Example:
ALTER TABLE Student DROP COLUMN Age;
This command will drop particular column.
Modifying Existing Table
Syntax:
ALTER TABLE table_name MODIFY (column_name NewDataType(NewSize));
Example:
ALTER TABLE Student MODIFY (Name Varchar2(40));
The Name column already exist in Student table, it was char and size 30, now it
is modified by Varchar2 and size 40.
Database Management System (DMS) Mr. S. Y. Divekar
RENAME Command:
The Rename table commandis used to rename the old table name
to new table name.

Syntax:
RENAME OldTableName TO NewTableName;

Example:
RENAME Student TO Stud;
The old name table was Student now new name is the Stu.

Database Management System (DMS) Mr. S. Y. Divekar


TRUNCATE Command:
Truncate table command is used to delete the whole rows of the
table.
The structure of the table remain as it is. You can add new data to
the table again.
Syntax:
TRUNCATE TABLE Table_name;

Example:
TRUNCATE TABLE Student;

Database Management System (DMS) Mr. S. Y. Divekar


DROP Command:
A table and its rows can be deleted by issuing the DROP TABLE
command.
Syntax:
DROP TABLE Table_name;

Example:
DROP TABLE Student;
It will destroy the table and all data which will be recorded in it.

Database Management System (DMS) Mr. S. Y. Divekar


Lecture :- 2.6 : Outlines
Data Integrity constraint

Database Management System (DMS) Mr. S. Y. Divekar


Integrity Constraints :
Integrity constraints are a set of rules. It is used to maintain the
quality of information.
Integrity constraints ensure that the data insertion, updating,
and other processes have to be performed in such a way that
data integrity is not affected.
Thus, integrity constraint is used to guard against accidental
damage to the database.
Types of Integrity Constraint

Database Management System (DMS) Mr. S. Y. Divekar


Domain constraints:
Domain constraints can be defined as the definition of a valid set
of values for an attribute.
The data type of domain includes string, character, integer, time,
date, currency, etc. The value of the attribute must be available in
the corresponding domain.
Example:

Database Management System (DMS) Mr. S. Y. Divekar


Entity integrity constraints:
The entity integrity constraint states that primary key value can't
be null.
This is because the primary key value is used to identify individual
rows in relation and if the primary key has a null value, then we
can't identify those rows.
A table can contain a null value other than the primary key field.
Example:

Database Management System (DMS) Mr. S. Y. Divekar


Referential Integrity Constraints:
A referential integrity constraint is specified between two tables.
In the Referential integrity constraints, if a foreign key in Table A
refers to the Primary Key of Table B, then every value of the
Foreign Key in Table A must be null or be available in Table B.
Example:

Database Management System (DMS) Mr. S. Y. Divekar


Key constraints:
Keys are the entity set that is used to identify an entity within its
entity set uniquely.
An entity set can have multiple keys, but out of which one key will
be the primary key. A primary key can contain a unique and null
value in the relational table.
Example:

Database Management System (DMS) Mr. S. Y. Divekar


Integrity constraints:

Database Management System (DMS) Mr. S. Y. Divekar


I / O constraints:
Constrains that control data insertion and data retrieval speed
are known as I/O (Input-Output) constraints.
It includes the following constraints.
1. Primary Key
2. Foreign Key
3. Unique Key

Database Management System (DMS) Mr. S. Y. Divekar


Primary Key constraints:
Primary key is used to identify a record uniquely from the
database table.
A primary key means UNIQUE + NOT NULL.
Value must be available for the column on which primary key has
been defined.
User cannot leave the field blank.
It cannot contain duplicate values.
Primary key can be defined either at table level or at column
level.
Primary key keyword is used to define primary key constraint

Database Management System (DMS) Mr. S. Y. Divekar


Primary Key constraints:
Syntax:
Create table table_name
(column_name1 datatype(size) Primary key,
column_name2 datatype(size),
……
column_nameN datatype(size));
Example:
CREATE TABLE Student
(Roll_no number(4) Primary key,
Name char(30),
DOB date,
Address varchar2(50));

Database Management System (DMS) Mr. S. Y. Divekar


Primary Key constraints:
Syntax:
ALTER TABLE Table_name ADD PRIMARY KEY (Col_name);

ALTER TABLE Table_name ADD CONSTRAINT CON_NAME


PRIMARY KEY (Col_name1, Col_name2);

ALTER TABLE Table_name DROP PRIMARY KEY ;


Example:
ALTER TABLE STUDENT ADD PRIMARY KEY (ROLLNO);
ALTER TABLE STUDENT ADD CONSTRAINT PK_STUDID PRIMARY
KEY (ROLLNO, NAME);
ALTER TABLE STUDENT DROP PRIMARY KEY ;

Database Management System (DMS) Mr. S. Y. Divekar


Foreign Key constraints:
A foreign key constraint is used to establish logical relationship
between two or more tables.
Foreign key is also known as referential key.
It can be defined using the keyword “references”.
Normally we can establish relationship between two or more
tables by using some common fields.
Generally a primary key is considered for defining relationship
with other tables.
The main table which is logically linked with other table is known
as ‘Parent table’ or “master table” while other table is referred to
as ‘Child table’ or “Slave table”.

Database Management System (DMS) Mr. S. Y. Divekar


Foreign Key constraints:
Syntax:
Parent table:
Create table Parent_table_name
(column_name1 datatype(size) Primary key,
column_name2 datatype(size),
……
column_nameN datatype(size));
Child table:
Create table Child_table_name
(column_name1 datatype(size),
column_name2 datatype(size),
column_nameN datatype(size),
FOREIGN KEY (Col_name) REFERENCES Parent_table_name
(Parent_Col_name));

Database Management System (DMS) Mr. S. Y. Divekar


Foreign Key constraints:
Example:
Parent table:
CREATE TABLE Department
(Dept_id number(4) Primary key,
Dept_Name char(30));
Child table:
CREATE TABLE Student
(Roll_no number(4) Primary key,
Name char(30),
DOB date,
Address varchar2(50),
Dept_no number(4),
FOREIGN KEY (Dept_no) REFERENCES Department (Dept_id));

Database Management System (DMS) Mr. S. Y. Divekar


Foreign Key constraints:
Syntax:
ALTER TABLE Table_name ADD
FOREIGN KEY (Col_name) REFERENCES Parent_table_name
(Parent_Col_name));

ALTER TABLE Table_name ADD CONSTRAINT Cost_Name


FOREIGN KEY (Col_name) REFERENCES Parent_table_name
(Parent_Col_name));

ALTER TABLE Table_name DROP FOREIGN KEY Cost_Name;

Database Management System (DMS) Mr. S. Y. Divekar


Foreign Key constraints:
Example:
ALTER TABLE Student ADD
FOREIGN KEY (Dept_no) REFERENCES Department (Dept_id));

ALTER TABLE Student ADD CONSTRAINT FK_Std


FOREIGN KEY (Dept_no) REFERENCES Department (Dept_id));

ALTER TABLE Student DROP FOREIGN KEY FK_Std;

Database Management System (DMS) Mr. S. Y. Divekar


Unique Key constraints:
A unique key constraint can be defined when we do not want the
user to enter duplicate values.
A unique constraint allows only unique value to be inserted.
However it allows null value to be inserted.
If the value is present for the unique constraint field then it must
be unique.
Similar to not null constraint unique key can also be define on
multiple columns.
“unique” keyword is use to define unique constraint.

Database Management System (DMS) Mr. S. Y. Divekar


unique Key constraints:
Syntax:
Create table table_name
(column_name1 datatype(size),
column_name2 datatype(size) unique,
column_nameN datatype(size));
Example:
CREATE TABLE Student
(Roll_no number(4),
Name char(30),
DOB date,
Mobile_no number(10) unique,
Address varchar2(50));

Database Management System (DMS) Mr. S. Y. Divekar


Unique Key constraints:
Syntax:
ALTER TABLE Table_name ADD UNIQUE (Col_name);

ALTER TABLE Table_name ADD CONSTRAINT CON_NAME


UNIQUE (Col_name1, Col_name2);

ALTER TABLE Table_name DROP INDEX CON_NAME;


Example:
ALTER TABLE STUDENT ADD UNIQUE (MOBILENO);
ALTER TABLE STUDENT ADD CONSTRAINT UK_STUD UNIQUE
(MOBILENO, NAME);
ALTER TABLE STUDENT DROP INDEX UK_STUD;

Database Management System (DMS) Mr. S. Y. Divekar


Business Rule constraints:
This rules are applied to data prior(first) the data being inserted
into the table columns.
It includes the following constraints.
1. NULL
2. NOT NULL
3. CHECK

Database Management System (DMS) Mr. S. Y. Divekar


NULL / NOT NULL constraints:
The NOT NULL constraint enforces a column to NOT accept NULL
values.
This enforces a field to always contain a value, which means that
you cannot insert a new record, or update a record without
adding a value to this field.
NOT NULL keyword is used to define NOT NULL constraint

Database Management System (DMS) Mr. S. Y. Divekar


NULL / NOT NULL constraints:
Syntax:
Create table table_name
(column_name1 datatype(size) NOT NULL ,
column_name2 datatype(size) NOT NULL ,
……
column_nameN datatype(size) NULL );
Example:
CREATE TABLE Student
(Roll_no number(4) Primary key,
Name char(30) NOT NULL ,
DOB date ,
Address varchar2(50) NULL );

Database Management System (DMS) Mr. S. Y. Divekar


NULL / NOT NULL constraints:
Syntax:
ALTER TABLE Table_name
MODIFY (Col_name Datatype(size) NOT NULL);
ALTER TABLE Table_name
MODIFY (Col_name Datatype(size) NULL);

Example:
ALTER TABLE STUDENT
MODIFY (Address varchar2(50) NOT NULL);
ALTER TABLE STUDENT
MODIFY (Address varchar2(50) NULL);

Database Management System (DMS) Mr. S. Y. Divekar


CHECK constraints:
Using the CHECK constraint we can specify a condition for a field,
which should be satisfied at the time of entering values for this
field.
SQL CHECK Constraint must be specified as a logical expression
that evaluated specific condition either TRUE or FALSE.
CHECK keyword is used to define CHECK constraint

Database Management System (DMS) Mr. S. Y. Divekar


CHECK constraints:
Syntax:
Create table table_name
(column_name1 datatype(size) CHECK (column_name condition),
column_name2 datatype(size),
……
column_nameN datatype(size) );
Example:
CREATE TABLE Student
(Roll_no number(4) Primary key,
Name char(30) CHECK ( Name = upper(Name) ),
DOB date,
Address varchar2(50) );

Database Management System (DMS) Mr. S. Y. Divekar


CHECK constraints:
Syntax:
ALTER TABLE Table_name
ADD CONSTRAINT check_constraint_name CHECK (column_name condition);

ALTER TABLE Table_name


DROP CONSTRAINT check_constraint_name;

Example:
ALTER TABLE STUDENT
ADD CONSTRAINT check_name CHECK (name = upper(name));

ALTER TABLE STUDENT


DROP CONSTRAINT check_name;
Database Management System (DMS) Mr. S. Y. Divekar
Lecture :- 2.7 : Outlines
DML commands-
INSERT,
UPDATE,
DELETE.

Database Management System (DMS) Mr. S. Y. Divekar


INSERT Statement / command:
The INSERT INTO statement is used to insert new records in a
table.
The SQL INSERT INTO Statement is used to add new rows of data
to a table in the database.
Rules:
1. The columns and values must match order, data type and
number.
2. If the column is of strings or date time or characters, they
need to be enclosed in the in the single quotes. If they’re
numeric, you don’t need the quotes.

Database Management System (DMS) Mr. S. Y. Divekar


Syntax:
It is possible to write the INSERT INTO statement in two ways.
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
If you are adding values for all the columns of the table, you do
not need to specify the column names in the SQL query.
INSERT INTO table_name
VALUES (value1, value2, value3, ...);
Example:
INSERT INTO student (Roll_no, Name, DOB, Address)
VALUES (001, ‘Krishna’,’01-Jul-2002’,’Shivaji nagar pune’);

INSERT INTO student


VALUES (002, ‘Sanchi’,’10-Sep-2013’,’Hadapsar pune’);

Database Management System (DMS) Mr. S. Y. Divekar


UPDATE Statement / command:
The SQL UPDATE Query is used to modify the existing records in a
table.
You can use the WHERE clause with the UPDATE query to update
the selected rows, otherwise all the rows would be affected.
We can update single columns as well as multiple columns using
UPDATE statement as per our requirement.

Database Management System (DMS) Mr. S. Y. Divekar


Syntax:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
Example:
Update Single row or record.
UPDATE student
SET Address = ‘Mumbai'
WHERE Roll_no = 001;
Update multiple records.
UPDATE student
SET Address = ‘Mumbai‘, DOB =‘01-jan-2006’
WHERE Roll_no = 001;

Database Management System (DMS) Mr. S. Y. Divekar


DELETE Statement / command:
The SQL DELETE Query is used to delete the existing records from
a table.
You can use the WHERE clause with a DELETE query to delete the
selected rows, otherwise all the records would be deleted.
We can delete a single record or multiple records depending on
the condition we specify in the WHERE clause.

Database Management System (DMS) Mr. S. Y. Divekar


Syntax:
DELETE FROM table_name
WHERE [condition];
Example:
Delete Single row or record.
DELETE FROM student
WHERE Roll_no = 001;
Delete multiple records.
DELETE FROM student;

Note:-DELETE all the records from the CUSTOMERS table, you do not
need to use the WHERE clause.

Database Management System (DMS) Mr. S. Y. Divekar


Lecture :- 2.9 : Outlines
 DQL COMMANDS :
SELECT

Database Management System (DMS) Mr. S. Y. Divekar


DQL (Data Query Language) COMMANDS :
DQL commands are used for fetching data from a relational
database. which returns this data in the form of a result table.
These result tables are called result-sets.
DML statements are used for performing queries on the data
within schema objects. The purpose of DQL Command is to get
some schema relation based on the query passed to it.
SELECT – is used to retrieve data from the a database.

Database Management System (DMS) Mr. S. Y. Divekar


Syntax:
SELECT expressions
FROM table_name
WHERE condition1, condition2,…., conditionN;
Expressions: The columns or calculations that you wish to
retrieve. Use * if you wish to select all columns.
WHERE conditions: Optional. The conditions that must be met for
the records to be selected. If no conditions are provided, then all
records will be selected.
Example:
SELECT * FROM Student:
SELECT Name, Address FROM Student
WHERE RollNo=001;

Database Management System (DMS) Mr. S. Y. Divekar


Syntax:
SELECT DISTINCT expressions
FROM table_name
WHERE condition1, condition2,…., conditionN;
DISTINCT: The SELECT DISTINCTcommand can also be used for
eliminating duplicates from a table.
Example:
SELECT DISTINCT * FROM Student:
SELECTDISTINCT Name, Address FROM Student
WHERE RollNo=001;

Database Management System (DMS) Mr. S. Y. Divekar


Lecture :- 2.10 : Outlines
 SQL OPERATOR :
Arithmetic,
Comparison,
Logical operator,
Set operator,
Range searching operators-between ,
Pattern matching operator-LIKE

Database Management System (DMS) Mr. S. Y. Divekar


SQL OPERATOR:
SQL statements generally contain some reserved words or
characters that are used to perform operations such as
comparison and arithmetical operations etc. These reserved
words or characters are known as operators..
Generally there are three types of operators in SQL:
SQL Arithmetic Operators.
SQL Comparison Operators.
SQL Logical Operators.

Database Management System (DMS) Mr. S. Y. Divekar


SQL Arithmetic Operators :
To perform calculations based on number values, we include
arithmetic expressions in SQL command. An arithmetic expression
consists of column names with number data type and an
arithmetic operators connecting them.

Example:
•SELECT SAL +10 FROM EMP; SELECT SAL - 10 FROM EMP;
•SELECT SAL * 10 FROM EMP; SELECT SAL / 10 FROM EMP;

Database Management System (DMS) Mr. S. Y. Divekar


SQL Comparison Operators :
Comparison Operators are used in conditions to compare one
expression with another.

Database Management System (DMS) Mr. S. Y. Divekar


SQL Comparison Operators :

Database Management System (DMS) Mr. S. Y. Divekar


SQL Logical Operators :
Logical operators which manipulate the results of conditions are
listed.

Database Management System (DMS) Mr. S. Y. Divekar


SQL Set Operators :
Set operators which combine the results of two queries into a
single result are listed .

Database Management System (DMS) Mr. S. Y. Divekar


Range searching operators:
Between:
The BETWEEN operator selects values within a given range. The
values can be numbers, text, or dates.
The BETWEEN operator is inclusive: begin and end values are
included.
Syntax:
SELECT column_name(s) FROM table_name
WHERE column_name BETWEEN value1 AND value2;
Example:
SELECT * FROM Student
WHERE Marks BETWEEN 80 AND 90;

Database Management System (DMS) Mr. S. Y. Divekar


Pattern matching operator :
LIKE:
The LIKE operator is used in a WHERE clause to search for a
specified pattern in a column.
There are two wildcards often used in conjunction with the LIKE
operator:
% - The percent sign represents zero, one, or multiple characters
_ - The underscore represents a single character
Syntax:
SELECT column_name(s) FROM table_name
WHERE columnN LIKE pattern;

Database Management System (DMS) Mr. S. Y. Divekar


Pattern matching operator : LIKE:
Example:
SQL statement selects all students with a Name starting with “s":
SELECT * FROM Student
WHERE Name LIKE ‘s%‘;
SQL statement selects all students with a Name ending with “a":
SELECT * FROM Student
WHERE Name LIKE ‘%a';
SQL statement selects all students with a Name that have "or" in
any position :
SELECT * FROM Student
WHERE Name LIKE ‘%or%';

Database Management System (DMS) Mr. S. Y. Divekar


Example:
SQL statement selects all students with a Name that have “a" in
the second position.
SELECT * FROM Student
WHERE Name LIKE ‘_a%‘;

SQL statement selects all students with a Name that starts with
"a" and are at least 3 characters in length:
SELECT * FROM Student
WHERE Name LIKE ’a__%';

SQL statement selects all students with a Name that starts with
"a" and ends with "o":
SELECT * FROM Student
WHERE Name LIKE ’a%o';

SQL statement selects all students with a Name that does NOT
start with "a":
SELECT * FROM Student
WHERE Name NOT LIKE ’a%';

Database Management System (DMS) Mr. S. Y. Divekar


Lecture :- 2.10 : Outlines
 TCL and DCL Commands :
COMMIT ,
SAVEPOINT ,
ROLLBACK,
GRANT ,
REVOKE.

Database Management System (DMS) Mr. S. Y. Divekar


TCL Commands :
Transaction Control Language(TCL) commands are used to
manage transactions in the database. These are used to manage
the changes made to the data in a table by DML statements. It
also allows statements to be grouped together into logical
transactions.
Transactional control commands are used only DML Commands
such as INSERT, UPDATE and DELETE.
Here are some commands that come under TCL:
1. COMMIT
2. ROLLBACK
3. SAVEPOINT

Database Management System (DMS) Mr. S. Y. Divekar


COMMIT :
COMMIT command is used to permanently save any transaction
into the database.
The COMMIT command saves all the transactions to the database
since the last COMMIT or ROLLBACK command.
Syntax:
COMMIT;
Example:
DELETE FROM Student
WHERE Marks = 85;
COMMIT;

Database Management System (DMS) Mr. S. Y. Divekar


ROLLBACK :
Rollback command restores the database to the last committed
state. ROLLBACK also used with the savepoint.
This transaction will revert back due to a violation of the primary
key.
Syntax:
ROLLBACK;
Example:
DELETE FROM Student
WHERE Marks = 85;
ROLLBACK;

Database Management System (DMS) Mr. S. Y. Divekar


SAVEPOINT :
Savepoint command is used to temporarily save a transaction so
that you can rollback to that point whenever necessary.
Syntax:
SAVEPOINT SAVEPOINT_NAME;

Example:
DELETE FROM Student
WHERE Marks = 85;
SAVEPOINT S1;

Database Management System (DMS) Mr. S. Y. Divekar


TCL Commands :
Example:
INSERT INTO class VALUES(5, 'Rahul');
COMMIT;
UPDATE class SET name = 'Abhijit' WHERE id = '5';
SAVEPOINT A;
INSERT INTO class VALUES(6, 'Chris');
SAVEPOINT B;
INSERT INTO class VALUES(7, 'Bravo');
SAVEPOINT C;
SELECT * FROM class;
ROLLBACK command
ROLLBACK TO B;
SELECT * FROM class;

Database Management System (DMS) Mr. S. Y. Divekar


DCL Commands :
Data Control Language(DCL) is used to control privileges in
Database. To perform any operation in the database, such as for
creating tables, sequences or views, a user needs privileges.
Privileges are of two types,
System: This includes permissions for creating session, table, etc
and all types of other system privileges.
Object: This includes permissions for any command or query to
perform any operation on the database tables.
DCL have two commands,
GRANT: Used to provide any user access privileges or other
priviliges for the database.
REVOKE: Used to take back permissions from any user.

Database Management System (DMS) Mr. S. Y. Divekar


GRANT :
Grants a privilege to a user It means that giving authority to other
user by administrator If you are administrator then only you have
authority for grating the other authority to other user Can grant
privilege only if you have been granted that privilege.
Syntax:
GRANT < Object Privileges > ON <ObjectName> TO <UserName>
[WITH GRANT OPTION];

Database Management System (DMS) Mr. S. Y. Divekar


OBJECT PRIVILEGES:
Each object privilege that is granted authorizes the grantee to
perform some operation on the object. A user can grant all the
privileges or grant only specific object privileges.
The list of object privileges is as follows:
ALTER : Allows the grantee to change the table definition with the
ALTER TABLE command
DELETE : Allows the grantee to remove the records from the table
with the DELETE command
INDEX : Allows the grantee to create an index on the table with the
CREATE INDEX command
INSERT : Allows the grantee to add records to the table with the
INSERT command
SELECT : Allows the grantee to query the table with the SELECT
command
UPDATE : Allows the grantee to modify the records in the tables
with the UPDATE command
Database Management System (DMS) Mr. S. Y. Divekar
GRANT :
Example:
Give the user POLY permission to only view and modify records in
the table Student.

GRANT SELECT, UPDATE ON Student TO POLY;

Grant succeeded.

Database Management System (DMS) Mr. S. Y. Divekar


REVOKE:
The REVOKE statement is used to deny the grant given on an
object. Revokes a privilege from a user It is use to taking off or
remove of authority or say getting back authority from user.
Syntax:
REVOKE < Object Privileges > ON <Object Name> FROM
<Username>;
Example:
All privileges on the table Student have been granted to POLY.
Take back the Delete privilege on the table.
REVOKE DELETE ON Student FROM POLY;
Revoke succeeded.

Database Management System (DMS) Mr. S. Y. Divekar


Thanks

Database Management System (DMS) Mr. S. Y. Divekar

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy