Documente Academic
Documente Profesional
Documente Cultură
Courses
Course Objective
In this course all the important aspects of Relation Database
Management System is covered in detail with appropriate examples.
Section 1 of this course covers how data and information was
organised before concept of database came into existense and then how
programming in computers changed dramatically after the introduction of
database systems. This section also talks about various database systems that
are available. Fuctions of RDBMS and role of DBA are also covered in detail.
Section 2 talks about tables and relationships. In this section the
reader would also get an insight on database normalizaton and the importance
of normalizing tables. Last topic in the section is Joins. By going thorugh joins
one would understand how data are fetched from two or more database tables
by applying joins.
Section 3 covers Structred Query Language (SQL). In this section
we would know more about how tables and databases are defined(DDL) and
how the data in the tables are maniuplated and controlled through data
manipulation language(DML) and data control language(DCL).
Course Content
1.
iii.
iv.
Functions of DBMS
v.
2.
https://aspire.tcs.com/aspire/courses/rdbms/index.html
1/2
12/9/13
i.
ii.
iii.
3.
iii.
iv.
Courses
https://aspire.tcs.com/aspire/courses/rdbms/index.html
2/2
12/9/13
RDBMS
1. Introduction to Database
Management Systems
https://aspire.tcs.com/aspire/courses/rdbms/module1/session1.1_introduction-approach-to-data-management-from-files-to-database_1.html
1/1
12/9/13
RDBMS
1. Introduction to Database
Management Systems
1/2
12/9/13
https://aspire.tcs.com/aspire/courses/rdbms/module1/session1.1_introduction-approach-to-data-management-from-files-to-database_2.html
2/2
12/9/13
RDBMS
1. Introduction to Database
Management Systems
1/2
12/9/13
https://aspire.tcs.com/aspire/courses/rdbms/module1/session1.1_introduction-approach-to-data-management-from-files-to-database_3.html
2/2
12/9/13
RDBMS
1. Introduction to Database
Management Systems
g. Recovery Issues
System failures or loss of connection to remote systems should be
dealt by the file system. In the event of operating system failure or "soft" power
failure, special routines in the file system must be invoked similar to individual
program failure. The damaged structures must also be corrected by the file
system . These may occur as a result of an operating system failure for which
the OS is not able to notify the file system, power failure or reset. The file
system must also record events to allow the analysis of systemic issues as well
as the problems with specific files or directories.For example, during the
admission process of students if there is a system failure, the non recovery of
data will cause issues (Figure 1.0).
It may be noted that, facing the above issues like concurrent
access, integrity security problems, etc., is possible in a file-based system.
Though all these are general issues of concern to any data-intensive
application (An application which processes huge volume of data
simultaneously), each application has to handle all these problems on its own.
The application programmer should bother not only about implementing the
application business process but also about handling these general issues.
https://aspire.tcs.com/aspire/courses/rdbms/module1/session1.1_introduction-approach-to-data-management-from-files-to-database_4.html
1/1
12/9/13
RDBMS
1. Introduction to Database
Management Systems
https://aspire.tcs.com/aspire/courses/rdbms/module1/session1.1_introduction-approach-to-data-management-from-files-to-database_5.html
1/1
12/9/13
RDBMS
1. Introduction to Database
Management Systems
https://aspire.tcs.com/aspire/courses/rdbms/module1/session1.2_types-of-data-bases_1.html
1/1
12/9/13
RDBMS
1. Introduction to Database
Management Systems
1/3
12/9/13
Advantages
This database type can be accessed and updated rapidly because
of the tree-like structure and the relationships between records
are defined in advance.
Disadvantages
https://aspire.tcs.com/aspire/courses/rdbms/module1/session1.2_types-of-data-bases_2.html
2/3
12/9/13
Each child in a tree may have only one parent and relationships
or linkages between the children are not permitted, even if they
seem right from a logical standpoint.
Hierarchical databases are so firm in their design that adding a
new field or record requires that the entire database be
redefined.
Course Contents | Prev : Next
https://aspire.tcs.com/aspire/courses/rdbms/module1/session1.2_types-of-data-bases_2.html
3/3
12/9/13
RDBMS
1. Introduction to Database
Management Systems
https://aspire.tcs.com/aspire/courses/rdbms/module1/session1.2_types-of-data-bases_3.html
1/1
12/9/13
RDBMS
1. Introduction to Database
Management Systems
Advantages
A lot of connections can be made between the different types of
data and the network databases, and they work more flexibly.
https://aspire.tcs.com/aspire/courses/rdbms/module1/session1.2_types-of-data-bases_4.html
1/2
12/9/13
Disadvantages
Network databases must be described in advance.
There is a limit to the number of connections which can be made
between records.
Course Contents | Prev : Next
https://aspire.tcs.com/aspire/courses/rdbms/module1/session1.2_types-of-data-bases_4.html
2/2
12/9/13
RDBMS
1. Introduction to Database
Management Systems
https://aspire.tcs.com/aspire/courses/rdbms/module1/session1.2_types-of-data-bases_5.html
1/2
12/9/13
https://aspire.tcs.com/aspire/courses/rdbms/module1/session1.2_types-of-data-bases_5.html
2/2
12/9/13
RDBMS
1. Introduction to Database
Management Systems
Advantage
The database server and application tools can be easily installed
and upgraded.
RDBMS permits multiple database users to access a database
simultaneously.
Authorization and privilege control features in an RDBMS permit
https://aspire.tcs.com/aspire/courses/rdbms/module1/session1.2_types-of-data-bases_6.html
1/2
12/9/13
Disadvantage
Searching for a data or information can take extra time as
compared to other methods.
* SSN is the unique id or number given to each citizen in USA
https://aspire.tcs.com/aspire/courses/rdbms/module1/session1.2_types-of-data-bases_6.html
2/2
12/9/13
RDBMS
1. Introduction to Database
Management Systems
https://aspire.tcs.com/aspire/courses/rdbms/module1/session1.3_advantages-of-database-system_1.html
1/2
12/9/13
https://aspire.tcs.com/aspire/courses/rdbms/module1/session1.3_advantages-of-database-system_1.html
2/2
12/9/13
RDBMS
1. Introduction to Database
Management Systems
https://aspire.tcs.com/aspire/courses/rdbms/module1/session1.3_advantages-of-database-system_2.html
1/1
12/9/13
RDBMS
1. Introduction to Database
Management Systems
https://aspire.tcs.com/aspire/courses/rdbms/module1/session1.3_advantages-of-database-system_3.html
1/2
12/9/13
https://aspire.tcs.com/aspire/courses/rdbms/module1/session1.3_advantages-of-database-system_3.html
2/2
12/9/13
RDBMS
1. Introduction to Database
Management Systems
b. Data Independence
Data and programs are independent of each other, so change is
one has no or minimum effect on the other. Data and its structure are stored in
the database where as application programs manipulating this data are stored
separately, the change in one does not necessarily affect the other.
c. Controlled Redundancy
This means that we do not have to duplicate the data
unnecessarily. We do duplicate data in the databases; however, this
duplication is deliberate and controlled.
1/2
12/9/13
that the data being entered into the database is actually valid.
Integrity of data is very important, since all the processing and
the information produced inturn are based on this data. If the data entered is
not valid, we cannot rely on the correctness of the results produced. The
business decisions are made based on the information present in the database
and invalid information leads to wrong decisions, and business inturn
collapses. In the database environment, DBMS provides many features to
ensure the integrity of data, hence we have more reliable data.
https://aspire.tcs.com/aspire/courses/rdbms/module1/session1.3_advantages-of-database-system_4.html
2/2
12/9/13
RDBMS
1. Introduction to Database
Management Systems
Characteristics
Database Approach
Data Redundancy
Data Consistency
Concurrent Access Anomalies
Security
Integrity
Recovery
https://aspire.tcs.com/aspire/courses/rdbms/module1/session1.3_advantages-of-database-system_5.html
1/1
12/9/13
RDBMS
1. Introduction to Database
Management Systems
a. Data Definition
The DBMS provides the functions to describe the structure of the
data in the application. These include defining and modifying the record
structure, the type and size of fields and the various constraints/conditions to
be satisfied by the data in each field.
1/2
12/9/13
Example:
In Figure1.9 Attributes such as Name, Email Address,.., State are
the defined columns of the Student table. Each column has specific length, type
and rules applicable to the corresponding columns. So here Attribute (i.e
Columns) represents data elements and Length, Type, Rules represent the data
definitions.
https://aspire.tcs.com/aspire/courses/rdbms/module1/session1.4_functions-of-database_1.html
2/2
12/9/13
RDBMS
1. Introduction to Database
Management Systems
https://aspire.tcs.com/aspire/courses/rdbms/module1/session1.4_functions-of-database_2.html
1/1
12/9/13
RDBMS
1. Introduction to Database
Management Systems
Data concurrency means that many users can access data at the
g. Performance
Optimizing the performance of the queries is one of the important
functions of a DBMS. The DBMS has a set of programs that form the Query
Optimizer which evaluates the different implementations of a query and
selects the best among them.
Thus the DBMS provides a convenient and effective environment
to use when a large volume of data and many transactions are to be processed
in the environment.
https://aspire.tcs.com/aspire/courses/rdbms/module1/session1.4_functions-of-database_3.html
1/2
12/9/13
https://aspire.tcs.com/aspire/courses/rdbms/module1/session1.4_functions-of-database_3.html
2/2
12/9/13
RDBMS
1. Introduction to Database
Management Systems
https://aspire.tcs.com/aspire/courses/rdbms/module1/session1.5_role-of-a-database-administrator_1.html
1/1
12/9/13
RDBMS
1. Introduction to Database
Management Systems
https://aspire.tcs.com/aspire/courses/rdbms/module1/session1.5_role-of-a-database-administrator_2.html
1/1
12/9/13
RDBMS
1. Introduction to Database
Management Systems
1/1
12/9/13
RDBMS
Example:
A university consists of a number of departments. Each
department offers several courses. Each course includes a number of modules.
Students enroll in a particular course and study modules towards the
completion of that course. Each module is taught by a lecturer from the
appropriate department, and each lecturer teaches a group of students.
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.1_entity-relationship-modeling_1.html
1/1
12/9/13
Entities
RDBMS
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.1_entity-relationship-modeling_2.html
1/1
12/9/13
RDBMS
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.1_entity-relationship-modeling_3.html
1/2
12/9/13
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.1_entity-relationship-modeling_3.html
2/2
12/9/13
RDBMS
Example:
SubModule is a good example for weak entity. The SubModule
will be meaningless without a Module entity and so it depends on the existence
of Module as shown in Figure 2.2
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.1_entity-relationship-modeling_4.html
1/1
12/9/13
RDBMS
Attributes in ER diagram
In an E/R Diagram attributes are represented by an oval.
A line is used to link an attribute to its entity.
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.1_entity-relationship-modeling_5.html
1/1
12/9/13
RDBMS
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.1_entity-relationship-modeling_6.html
1/1
12/9/13
RDBMS
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.1_entity-relationship-modeling_7.html
1/1
12/9/13
RDBMS
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.1_entity-relationship-modeling_8.html
1/1
12/9/13
RDBMS
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.1_entity-relationship-modeling_9.html
1/2
12/9/13
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.1_entity-relationship-modeling_9.html
2/2
12/9/13
RDBMS
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.1_entity-relationship-modeling_10.html
1/2
12/9/13
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.1_entity-relationship-modeling_10.html
2/2
12/9/13
RDBMS
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.1_entity-relationship-modeling_11.html
1/1
12/9/13
RDBMS
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.1_entity-relationship-modeling_12.html
1/1
12/9/13
RDBMS
1/2
12/9/13
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.1_entity-relationship-modeling_13.html
2/2
12/9/13
RDBMS
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.1_entity-relationship-modeling_14.html
1/1
12/9/13
Introduction-Normalization
RDBMS
Advantages
Smaller, simpler and well-structured relations.
Avoids unnecessary duplication of data. That is, it helps to
reduce redundancy.
Provides data integrity.
Helps to avoid update anomalies. That is, it isolates data so that
additions, deletions, and modifications of a field can be made in
just one table. The changes are then propagated to the rest of the
database through the defined relationships.
Save storage space.
Course Contents | Prev : Next
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.2_introduction-to-normalization_1.html
1/1
12/9/13
Normalization
RDBMS
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.2_introduction-to-normalization_2.html
1/1
12/9/13
Primary Key
RDBMS
1/2
12/9/13
Primary Key
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.2_introduction-to-normalization_3.html
2/2
12/9/13
Primary Key
RDBMS
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.2_introduction-to-normalization_4.html
1/1
12/9/13
Composite Key
RDBMS
Student Table
StudentId
TestId
Mark
101
T001
400
101
T002
380
102
T001
290
103
T001
430
103
T003
410
103
T001
390
Table 2.1
Course Contents | Prev : Next
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.2_introduction-to-normalization_5.html
1/1
12/9/13
Functional Dependency
RDBMS
Lecturer
StudentId Name Dept_No Dept_Name Languages Known
In
Designation
Charge
101
Kevin
D001
CSE
102
James
D002
ECE
Williams
Professor
Table 2.2
Course Contents | Prev : Next
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.2_introduction-to-normalization_6.html
1/1
12/9/13
RDBMS
Languages Lecturer In
Designation
Known
Charge
101
Kevin
D001
CSE
English
Jacobs
Asst.Professor
101
Kevin
D001
CSE
Hindi
Jacobs
Asst.Professor
101
Kevin
D001
CSE
Tamil
Jacobs
Asst.Professor
102
James
D002
ECE
English
Williams
Professor
102
James
D002
ECE
Hindi
Williams
Professor
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.2_normalization-first-normalform_1.html
1/1
12/9/13
RDBMS
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.2_normalization-second-normalform_1.html
1/1
12/9/13
Partial dependency
RDBMS
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.2_normalization-second-normalform_2.html
1/1
12/9/13
RDBMS
Name
Dept_No
101
Kevin
D001
102
James
D002
Table 2.4
Department
Lecturer
Dept_No Dept_Name
In
Designation
Charge
D001
CSE
D002
ECE
Jacobs
Asst.
Professor
Williams Professor
Table 2.5
Languages
StudentId
Languages known
101
English
101
Hindi
101
Tamil
102
English
101
Hindi
Table 2.6
Course Contents | Prev : Next
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.2_normalization-second-normalform_3.html
1/1
12/9/13
RDBMS
Student
StudentId
Name
Dept_No
101
Kevin
D001
102
James
D002
Table 2.7
1/2
12/9/13
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.2_normalization-second-normalform_4.html
2/2
12/9/13
Foreign Key
RDBMS
Referential integrity
It is a concept used in database to ensure that there is consistency
in table relationships. If one table has a foreign key to another table, then the
concept of referential integrity states that you cannot add a record to the table
that contains the foreign key unless there is a corresponding record in the
link/relationship with the other table.
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.2_normalization-second-normalform_5.html
1/1
12/9/13
Referential Integrity
RDBMS
Student
StudentId
Name
Dept_No
101
Kevin
D001
102
James
D002
103
Annie
D003
Table 2.8
Department
Dept_No Dept_Name
Lecturer In Charge
Designation
D001
CSE
Jacobs
Asst. Professor
D002
ECE
Williams
Professor
Table 2.9
Transitive functional dependencies
When changing a non-key column might cause any of the other
non-key columns to change, it is called transitive functional dependency.
Attributes that are not a part of the key must not depend on any non-key
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.2_normalization-second-normalform_6.html
1/2
12/9/13
Referential Integrity
attribute.
Consider the table 2.9. Changing the non-key column Lecturer In
Charge , may change Designation. Here Dept_No acts as the key. All other
columns are non-key attributes. As per 3NF non-key attributes should not be
dependent on any other non-key attributes but 'Lecturer In Charge' is
dependent on 'Designation'. Both Lecturer In Charge and Designation are nonkey attributes. So it forms transitive dependency. So, to satisfy 3NF let's split
the table in a short while.
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.2_normalization-second-normalform_6.html
2/2
12/9/13
RDBMS
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.2_normalization-third-normalform_1.html
1/2
12/9/13
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.2_normalization-third-normalform_1.html
2/2
12/9/13
RDBMS
Name
Dept_No
101
Kevin
D001
102
James
D002
Table 2.10
Department
Dept_No
Dept_Name
LecturerId
D001
CSE
L01
D002
ECE
L02
Table 2.11
Lecturer
LecturerId LecturerName
Design
L01
Jacob
Asst.Professor
L02
Williams
Professor
Table 2.12
Languages
StudentId
Languages known
101
English
101
Hindi
101
Tamil
102
English
101
Hindi
Table 2.13
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.2_normalization-third-normal-form_2.html
1/2
12/9/13
Table 2.13
The example given above cannot be decomposed further to attain
higher forms of normalization because it is already normalized to the highest
level.Normally only complex data bases would need next levels of
normalization.
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.2_normalization-third-normal-form_2.html
2/2
12/9/13
RDBMS
2.3 Joins
What are Joins?
A join is a technique where records from two or more tables are
retrieved through a single SQL query and shown as a single output. As it forms
a set, It can be saved as a table or used as it is. A join is a means of combining
columns from two tables by using values common to both tables. It allow us to
combine data from more than one table into a single result set. A join condition
is used in the WHERE clause of select, update and delete queries.
Note: The query will give results from two tables as Cartesian
product(A Cartesian product is defined as all possible combinations of rows in
all tables). If join condition is omitted. The first table's rows are joined with all
rows of the second table. For example, if the first table has 30 rows and the
second table has 10 rows, the result will be 30 * 10, or 300 rows. This query will
take a long time to execute.
Let's use the two tables below to explain the join conditions.
Name
Dept_No
101
Kevin
1001
102
James
1002
103
Jacobs
1001
104
Williams
1001
105
Jose
1003
106
Jack
1003
107
Rob
1004
Table 2.14
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.3_introduction_joins_1.html
1/2
12/9/13
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.3_introduction_joins_1.html
2/2
12/9/13
RDBMS
2.3 Joins
Database table "Department"
Dept_No
Dept_Name
1001
CSE
1002
ECE
1003
EEE
1004
CIVIL
Table 2.15
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.3_introduction_joins_2.html
1/1
12/9/13
RDBMS
2.3 Joins
Lets consider a scenario to retrieve the details of student who
belong to 'CSE' department. We have to join two tables based on the common
column present in the two tables.
StudentId
name
dept_no dept_name
101
Kevin
1001
CSE
103
Jacobs
1001
CSE
104
Williams
1001
CSE
Table 2.16
Course Contents | Prev : Next
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.3_introduction_joins_3.html
1/1
12/9/13
RDBMS
2.4 Summary
The Entity-Relationship model (or ER model) is a way of
graphically representing the logical relationships of objects in
order to create a database.
An ER model is a graphical representation which contains
entities or "items", relationships among them and attributes of
the entities and the relationships.
The database design technique which is used to organize tables
in a manner that reduces redundancy and dependency of data is
called as Normalization.
There are three forms of normalization. They are First Normal
form(1NF),Second Normal form(2NF) and Third Normal
form(3NF).
A key is a value used to uniquely identify a row in a table. One or
more columns could be used to form a key for a table.
A primary key is a single column value used to identify a
database record uniquely.
A composite key is a primary key derived by combining multiple
columns and is used to identify a record uniquely.
The field in a table which matches the primary key column of
another table is called as foreign key. The cross-reference tables
can be achieved by foreign key.
First Normal Form-The multi-valued attributes (called repeating
groups) should be removed i.e. elimination of repeating groups.
All attributes must be atomic.
Second Normal Form- Partial functional dependencies must be
removed. The attributes that are not a part of the key should be
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.4_summary.html
1/2
12/9/13
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.4_summary.html
2/2
12/9/13
RDBMS
2.5 Webliography
http://jcsites.juniata.edu/faculty/rhodes/dbms/ermodel.htm
http://www.phlonx.com/resources/nf3/
http://www.w3schools.com/sql/sql_join.asp
https://aspire.tcs.com/aspire/courses/rdbms/module2/session2.5_webliography.html
1/1
12/9/13
Introduction Relational Data Base Management System (RDBMS) & Structured Query Language (SQL ) -- TATA Consultancy Services Pvt. Ltd.
RDBMS
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.1_introduction-relational-data-base-management-system-and-structured-query-language_1.
1/2
12/9/13
Introduction Relational Data Base Management System (RDBMS) & Structured Query Language (SQL ) -- TATA Consultancy Services Pvt. Ltd.
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.1_introduction-relational-data-base-management-system-and-structured-query-language_1.
2/2
12/9/13
Introduction Relational Data Base Management System (RDBMS) & Structured Query Language (SQL ) -- TATA Consultancy Services Pvt. Ltd.
RDBMS
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.1_introduction-relational-data-base-management-system-and-structured-query-language_2.
1/1
12/9/13
Introduction Relational Data Base Management System (RDBMS) & Structured Query Language (SQL ) -- TATA Consultancy Services Pvt. Ltd.
RDBMS
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.1_introduction-relational-data-base-management-system-and-structured-query-language_3.
1/1
12/9/13
RDBMS
data_type - is the data type for the column like char, date, number
1/2
12/9/13
table.
Constraints are optional for the columns.
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.2_introduction-to-data-definition-language_1.html
2/2
12/9/13
RDBMS
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.2_introduction-to-data-definition-language_2.html
1/1
12/9/13
RDBMS
CHAR: The CHAR data type is used for storing fixed length
character strings with a maximum size of 2000 bytes. The
CHAR(n) holds fixed length of n characters.
II.
III.
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.2_introduction-to-data-definition-language_3.html
1/1
12/9/13
RDBMS
Example1:
With the help of CREATE statement, let's create Students table
with columns as RollNo, Name and Phone as shown below.
CREATE TABLE Students (
RollNo NUMBER PRIMARY KEY,
Name CHAR(25) NOT NULL,
Phone NUMBER
);
Note: NULL specifies that the column doesn't have any value or
the column is empty.
1/1
12/9/13
RDBMS
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.2_introduction-to-data-definition-language_5.html
1/2
12/9/13
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.2_introduction-to-data-definition-language_5.html
2/2
12/9/13
RDBMS
1/2
12/9/13
FOREIGN
KEY
REFERENCES
);
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.2_introduction-to-data-definition-language_6.html
2/2
12/9/13
RDBMS
Example1:
The following command is used to permanently remove the
Students table structure/definition along with the data that was created.
DROP TABLE Students;
Example2:
Let's see how the employees table definition/structure is removed
from the database.
DROP TABLE employees;
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.2_introduction-to-data-definition-language_7.html
1/2
12/9/13
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.2_introduction-to-data-definition-language_7.html
2/2
12/9/13
RDBMS
Example:
Let's see how we can alter or edit the structure of the Students
table that we created using CREATE statement in Section 3.2.1 using SQL
queries. Let's assume that we have to add a new column called 'gender' to the
existing Students table .
ALTER TABLE Students ADD gender CHAR(10);
In the above example the "gender" column with the data type as
CHAR(10) has been added to the existing Students table.
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.2_introduction-to-data-definition-language_8.html
1/1
12/9/13
RDBMS
Example:
In the example below Unique constraint is applied to Phone
column in order to avoid duplicate phone numbers getting inserted into the
table.
ALTER TABLE employees ADD UNIQUE Phone;
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.2_introduction-to-data-definition-language_9.html
1/1
12/9/13
RDBMS
Example:
In the example below Unique constraint is applied to Phone
column in order to avoid duplicate phone numbers getting inserted into the
table.
ALTER TABLE employees ADD UNIQUE Phone;
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.2_introduction-to-data-definition-language_9.html
1/1
12/9/13
Introduction to Data Manipulation Language (DML) -- TATA Consultancy Services Pvt. Ltd.
RDBMS
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.3_introduction-to-data-manipulation-language_1.html
1/1
12/9/13
Introduction to Data Manipulation Language (DML) -- TATA Consultancy Services Pvt. Ltd.
RDBMS
Example 1:
Now let's see how to insert the details of students into Students
table. The following is the structure of the Students table. Let's see how to
insert the details of a student named David.
Name
Null?
Type
RollNo
NOT NULL
NUMBER
Name
NOT NULL
CHAR(25)
Phone
NUMBER
Gender
CHAR(10)
Table 3.1
Course Contents | Prev : Next
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.3_introduction-to-data-manipulation-language_2.html
1/1
12/9/13
Introduction to Data Manipulation Language (DML) -- TATA Consultancy Services Pvt. Ltd.
RDBMS
In the above query we have given values only for three columns
(RollNo, Name, Gender). Though we didn't mention Phone, the record will be
successfully inserted because it is not mandatory to provide values for the
columns which can accept NULL values during insertion. In Students table
Phone and Gender are the columns which can accept NULL values. For Peter's
record Phone column will be empty.
The data we inserted is represented in the table below:
RollNo Name
100
David
200
Peter
Phone
Gender
9830028200
Male
Male
Table 3.2
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.3_introduction-to-data-manipulation-language_3.html
1/2
12/9/13
Introduction to Data Manipulation Language (DML) -- TATA Consultancy Services Pvt. Ltd.
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.3_introduction-to-data-manipulation-language_3.html
2/2
12/9/13
Introduction to Data Manipulation Language (DML) -- TATA Consultancy Services Pvt. Ltd.
RDBMS
Null?
Type
Employee_Id
NOT NULL
NUMBER
First_Name
CHAR(10)
Last_Name
NOT NULL
CHAR(10)
NOT NULL
CHAR(25)
Phone_Number
NOT NULL
NUMBER
Hire_Date
NOT NULL
DATE
Job_ID
NOT NULL
CHAR(10)
Salary
NUMBER
Commission_PCT
NUMBER
Manager_ID
NUMBER
Age
NUMBER
Department_ID
NUMBER
Table 3.3
Query:
INSERT
INTO
(First_Name,Last_Name,Email,Phone_Number,
employees
Hire_Date,Job_ID,Salary,Commission_PCT,Manager_ID,Age,Department_ID)
VALUES ('George', 'Gordon','GGORDON',6505062222,
'01-JAN-07','SA_REP',9000,.1,148,25,80);
Result:
ERROR at line 1:
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.3_introduction-to-data-manipulation-language_4.html
1/2
12/9/13
Introduction to Data Manipulation Language (DML) -- TATA Consultancy Services Pvt. Ltd.
ORA-01400:
cannot
("E668292"."EMPLOYEES"."EMPLOYEE_ID")
insert
NULL
into
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.3_introduction-to-data-manipulation-language_4.html
2/2
12/9/13
Introduction to Data Manipulation Language (DML) -- TATA Consultancy Services Pvt. Ltd.
RDBMS
George
James
Gordon
GGordon
6505062222
148
25
80
Keats
j_keats
@gmail.com
6505062221
148
25
80
Table 3.4
Course Contents | Prev : Next
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.3_introduction-to-data-manipulation-language_5.html
1/1
12/9/13
Introduction to Data Manipulation Language (DML) -- TATA Consultancy Services Pvt. Ltd.
RDBMS
Syntax:
SELECT
search_condition
column_list
FROM
table_name
WHERE
where
column_list includes one or more columns from which data is
retrieved.
table_name is the name of the table from which the information
is retrieved.
search_condition specifies the conditions based on which rows
will be retrieved.
The three clauses used in the SELECT statement:
Clause
Description
SELECT
FROM
1/2
12/9/13
Introduction to Data Manipulation Language (DML) -- TATA Consultancy Services Pvt. Ltd.
clause is optional.
Table 3.5
Course Contents | Prev : Next
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.3_introduction-to-data-manipulation-language_6.html
2/2
12/9/13
Introduction to Data Manipulation Language (DML) -- TATA Consultancy Services Pvt. Ltd.
RDBMS
David
200
Peter
Phone
Gender
9830093024
Male
Male
Table 3.6
Here * denotes all the columns and rows of the table.
Example 2:
Let's assume that we want to select a row from Students table
whose roll no is 200.
To retrieve this the following query is executed.
SELECT name FROM Students WHERE RollNo=200;
Result:
Name
Peter
Table 3.7
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.3_introduction-to-data-manipulation-language_7.html
1/2
12/9/13
Table 3.7
Introduction to Data Manipulation Language (DML) -- TATA Consultancy Services Pvt. Ltd.
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.3_introduction-to-data-manipulation-language_7.html
2/2
12/9/13
Introduction to Data Manipulation Language (DML) -- TATA Consultancy Services Pvt. Ltd.
RDBMS
There are chances that there are more than one employees with
first name as George. The above query will retrieve all the employees whose
first name is George. But if we need only one specific employee whose first
name is George then we can add one more condition in WHERE clause which
will help in retrieving the exact required data.
SELECT Salary FROM employees
WHERE first_name= 'George' AND employee_id= 10 ;
Result:
Salary
9000
Table 3.8
In the above query we have added two conditions with the help of
the "AND" key word. AND checks for both the conditions and will retrieve the
record which matches both. So salary of the employee(i.e George as shown in
result) is retrieved from the employees table whose FIRST_NAME is "George"
and EMPLOYEE_ID is equal to 10.
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.3_introduction-to-data-manipulation-language_8.html
1/2
12/9/13
Introduction to Data Manipulation Language (DML) -- TATA Consultancy Services Pvt. Ltd.
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.3_introduction-to-data-manipulation-language_8.html
2/2
12/9/13
Introduction to Data Manipulation Language (DML) -- TATA Consultancy Services Pvt. Ltd.
RDBMS
Joins:
Join command is used to combine records from two or more
tables in a database. Join command creates a set that can be saved as a table or
used as it is.
A Join is a means of combining fields from two tables by using
values common to each other.
A Join condition can be used in the WHERE clause of SELECT,
UPDATE, DELETE statements. (Refer Section 2 in this document for more
details)
The following is the syntax for joining two tables:
SELECT col1, col2, col3... FROM table_name1, table_name2
WHERE table_name1.col2 = table_name2.col1;
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.3_introduction-to-data-manipulation-language_9.html
1/1
12/9/13
Introduction to Data Manipulation Language (DML) -- TATA Consultancy Services Pvt. Ltd.
RDBMS
Department_Name
80
Sales
Table 3.9
Phone
_Number
Hire
_Date
Job_ID Salary
Commission Manager
Department
Age
_PCT
_ID
_ID
10
148
25
80
11
James
j_keats
6505062221 01/01/07 SA_REP 7000
@gmail.com
148
25
80
Keats
Table 3.10
The column that is common between the two tables is Department_ID. So using
Department_ID we can join Department table and employees table. Please find below query for the same.
SELECT employee_Id, first_name,department_name,department_id
FROM department,employees
WHERE department.department _id = employees.department_id;
Result:
Employee_Id
First_Name
Department_Name
Department_ID
10
George
Sales
80
11
James
Sales
80
Table 3.11
Here data from employees table and department table are joined and displayed.
Department_Id from department table is compared with Department_Id from employees table
and the records that have same value for Department_ Id(i,e. 80) have been displayed.
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.3_introduction-to-data-manipulation-language_10.html
1/1
12/9/13
Introduction to Data Manipulation Language (DML) -- TATA Consultancy Services Pvt. Ltd.
RDBMS
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.3_introduction-to-data-manipulation-language_11.html
1/1
12/9/13
Introduction to Data Manipulation Language (DML) -- TATA Consultancy Services Pvt. Ltd.
RDBMS
Example 1:
RollNo Name
100
David
200
Peter
Phone
Gender
9830093024
Male
Male
Table 3.12
Let's update the Name "David" in the students tables to "John".
We use the below query for the same.
UPDATE students SET name = 'John' WHERE rollno = 100;
Result:
1 row updated.
Students table will look like this now:
RollNo Name
100
John
200
Peter
Phone
Gender
9830093024
Male
Male
Table 3.13
Course Contents | Prev : Next
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.3_introduction-to-data-manipulation-language_12.html
1/1
12/9/13
Introduction to Data Manipulation Language (DML) -- TATA Consultancy Services Pvt. Ltd.
RDBMS
Phone
_Number
Hire
_Date
Job_ID Salary
Commission Manager
Department
Age
_PCT
_ID
_ID
10
148
25
80
11
James
j_keats
6505062221 01/01/07 SA_REP 7000
@gmail.com
148
25
80
Keats
Table 3.14
Now we want to update the salary of the employee whose manager_ID is 148.
We use the below query for the same.
UPDATE employees SET salary = 10500 WHERE manager_id = 148;
Result:
2 rows updated.
In the above query employees table is updated with the salary value 10500 for the rows which
have the manager_id as 148.
There were two rows which had manager_id as 148 and they have been updated with salary
value as 10500 from 9000 and 7000 respectively.
employees table will look like this now:
Employee First
Last
_Id
_Name _Name
Phone
_Number
Hire
_Date
Job_ID Salary
Commission Manager
Department
Age
_PCT
_ID
_ID
10
148
25
80
11
James
j_keats
6505062221 01/01/07 SA_REP 10500
@gmail.com
148
25
80
Keats
Table 3.15
Course Contents | Prev : Next
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.3_introduction-to-data-manipulation-language_13.html
1/1
12/9/13
Introduction to Data Manipulation Language (DML) -- TATA Consultancy Services Pvt. Ltd.
RDBMS
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.3_introduction-to-data-manipulation-language_14.html
1/1
12/9/13
Introduction to Data Manipulation Language (DML) -- TATA Consultancy Services Pvt. Ltd.
RDBMS
John
200
Peter
Phone
Gender
9830093024
Male
Male
Table 3.16
If we want to delete a row from the above table whose RollNo is
100, we use the below query.
DELETE FROM Students WHERE ROLLNO = 100;
Result:
1 row deleted.
After deleting the record, Students table will look like this:
RollNo
Name
200
Peter
Phone
Gender
Male
Table 3.17
Course Contents | Prev : Next
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.3_introduction-to-data-manipulation-language_15.html
1/1
12/9/13
Introduction to Data Manipulation Language (DML) -- TATA Consultancy Services Pvt. Ltd.
RDBMS
Phone
_Number
Hire
_Date
Job_ID Salary
Commission Manager
Department
Age
_PCT
_ID
_ID
10
148
25
80
11
James
j_keats
6505062221 01/01/07 SA_REP 10500
@gmail.com
148
25
80
Keats
Table 3.18
Now let's delete the employee details whose hire date is 1st Jan 07.
DELETE FROM employees WHERE hire_date = '01-JAN-07';
Result:
2 rows deleted.
Two rows which have the Hire_Date value as '01-JAN-07' have been deleted from employees
table (Refer Example 2 of Sec3.2.1).
Note : The DELETE statement is different from the DROP statement. The DELETE statement
deletes some (or all) data from the table but the table exists in the data base. The DROP statement removes
the table permanently from the data base.
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.3_introduction-to-data-manipulation-language_16.html
1/1
12/9/13
RDBMS
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.4_introduction-to-data-control-language_1.html
1/1
12/9/13
RDBMS
Example:
GRANT SELECT ON employees TO user10;
to user10.
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.4_introduction-to-data-control-language_2.html
1/1
12/9/13
RDBMS
Example:
REVOKE SELECT ON employees FROM user10;
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.4_introduction-to-data-control-language_3.html
1/1
12/9/13
RDBMS
Summary:
DDL
Data Definition Language (DDL) statements are used to define,
modify or remove the table structure.
Commands:
CREATE - This command is used to create objects in the database
ALTER - It alters the structure of the database
database
DML
Data Manipulation Language (DML) statements are used for
managing data within the database.
Commands:
SELECT - retrieve data from the table
INSERT - The data is insert into a table
UPDATE - It updates existing data with new data within a table
DELETE - It deletes the records from a table but the space for the
records remain
DCL
Data Control Language (DCL) statements:
Commands:
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.4_summary.html
1/2
12/9/13
https://aspire.tcs.com/aspire/courses/rdbms/module3/session3.4_summary.html
2/2