2. Database
• It is collection of data items stored in one place and having something
common between them.
• Example – A librarian maintain a database of all the information related to
the books that are available in the library.
3. DBMS - Database Management System
• It is a collection of software or programs which help user in creation and
maintenance of a database.
• It is the software system that helps in the process of defining, constructing,
manipulating the database.
• Some of the popular DBMS’s are MySQL, Oracle, Sybase, etc.
4. RDBMS
• RDBMS stands for Relational Database Management System.
• RDBMS is a program used to maintain a relational database.
• All modern database management systems like SQL, MS SQL server, Oracle,
My SQL and Microsoft Access are based on RDBMS.
5. SQL – Structured Query Language
• SQL is the standard language for dealing with relational databases.
• It is a computer language for storing, manipulating and retrieving data stored
in relational databases.
• SQL can be used to insert, update, delete, search database records.
6. SQL Commands
• DDL – Data Definition Language
• DML – Data Manipulation Language
• DCL – Data Control Language
• DQL - Data Query Language
7. DDL – Data Definition Language
• This statements are used to build & modify the structure of your tables &
other objects in the database.
• DDL commands are:
CREATE – To create database objects
ALTER – To modify structure of database objects
DROP – To remove database objects
RENAME – To rename database objects
TRUNCATE – to empty the database table
8. DML -Data Manipulation Language
• DML statements are used for manipulating or managing data in a database.
• DML commands are:
• INSERT – Insert data into table
• UPDATE – Update data of table
• DELETE – Delete data from table
9. DCL – Data Control Language
• DCL statements is used to control the various user actions in the database.
• DCL commands are:
• GRANT – Gives some privilege to user for performing task on database.
• REVOKE – Take back permissions given from user.
10. DQL – Data Query Language
• DQL statements are used for performing queries on the data within schema
objects.
• DQL commands are:
• SELECT – Select data and display data from table.
11. SQL Comments
• Single line comments –
• Single line comments start with “—”.
• Any text between -- and the end of the line will be ignored.
• Multi-line comments –
• Multi-line comments start with “/*” and end with “*/”.
• Any text between /* and */ will be ignored.
12. SQL Operators
• An operator is a reserved word or a character used primarily in an SQL statement's
WHERE clause to perform operation(s), such as comparisons and arithmetic
operations.
• They are:
Arithmetic Operators:- +, -, /, %, *
Comparison Operators:- =, >, <, >=, <=, <>
Logical Operators:- AND, BETWEEN, IN, LIKE, NOT, OR, EXITS
Bitwise Operators:- &, |, ^
Compound Operators:- +=, -=, *=, /=, %=, &=, |*=, ^-=
13. WHERE Clause
• The WHERR Clause is used to filter the records.
• The SQL WHERE Clause is used to specify a condition while fetching the
data from single table or joining with multiple tables.
• Syntax -
14. ORDER BY Clause
• It is used to sort the data in ascending or descending order, based on one or
more columns.
• Some databases sorts query results in ascending order by default.
• We can use more than one column in the ORDERBY Clause.
• Syntax –
• SELECT column FROM table_name [WHERE Condition] [ORDERBY
column1….ColumnN] [ASC | DESC];
15. Group By Clause
• It is used in collaboration with the SELECT statement to arrange identical
data into groups.
• Syntax –
• SELECT column1, column2 FROM table_name [WHERE Condition]
GROUPBY column1, column2 ORDERBY column1, Column2;
16. SQL Joins
• It is used to combine row from two or more tables, based on a related
column between them.
• Types:
Inner Join
Left Outer Join
Right Outer Join
Full Outer Join
Cross Join
17. Types of Joins
Inner Join – Returns records that have matching values in both tables.
Left Outer Join – Returns all records from left table, and the matched records from
the right table.
Right Outer Join – Returns all records from right table, and the matched records
from the left table.
Full Outer Join – Returns all records when there is a match in either left or right
table.
Cross Join – Returns all records where each row of the first table is combined with
each row from the second table.
18. Delete vs Drop vs Truncate
Delete Drop Truncate
DML Command DDL Command DDL Command
Delete is used to delete the
records in the table.
Drop is used to drop the table
as well as table structure.
Truncate is used to delete the data
and keep the table structure as it is.
Delete statement can be rollback
before the commit.
Drop statement can’t rollback. Truncate statement can’t rollback.
19. DBMS Keys
• A DBMS keys is an attribute or a set of attributes which help you uniquely identify a
record or a row of data in a relation (table).
• Types of keys:
Super key
Primary Key
Candidate key
Foreign Key
Unique Key
20. Types of Keys
• Super Key – Super key is a set of one or more attributes that uniquely identifies
each record with in a table.
• Candidate Key – Candidate key is a minimal super key, which contains no extra
attributes. It consists of maximum possible attributes, which uniquely identifies.
• Primary Key – Primary key is an attribute, which is uniquely identifies each record
with in a table.
• Foreign Key – A foreign key are attributes in a table, whose value match as primary
key in another table.
• Unique Key - A unique key is a set of one or more than one fields/columns of a
table that uniquely identify a record in a database table.
21. Primary Key vs Unique Key
Primary Key Unique Key
Helps to identify a unique row from a table.
Helps to maintains unique data in a column of a
table.
Does not allow null values. Nulls are allowed.
A table can have only one primary key. There can be multiple unique keys in a table.