0% found this document useful (0 votes)
18 views32 pages

SQL Fundamentals, DDL, DML, DCL

SQL, or Structured Query Language, is a standard language used for managing and manipulating data in Relational Database Management Systems (RDBMS). It encompasses various commands categorized into DDL, DML, DCL, TCL, and DQL, allowing users to create, read, update, and delete database structures and data. SQL is widely applicable across industries for tasks such as data retrieval, analysis, and web development.

Uploaded by

aashdeepsingh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views32 pages

SQL Fundamentals, DDL, DML, DCL

SQL, or Structured Query Language, is a standard language used for managing and manipulating data in Relational Database Management Systems (RDBMS). It encompasses various commands categorized into DDL, DML, DCL, TCL, and DQL, allowing users to create, read, update, and delete database structures and data. SQL is widely applicable across industries for tasks such as data retrieval, analysis, and web development.

Uploaded by

aashdeepsingh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 32

SQL Fundamentals,

DDL, DML, DCL.


What is SQL?
• SQL stands for Structured Query Language.
• It is used for storing and managing data in Relational
Database Management System (RDBMS).
• Which guideline proved by Standard Organization
ANSI
• 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.
• SQL allows users to query the database in a number
of ways, using English-like statements.
What are the SQL?
SQL follows the following rules:
• Structure query language is not case sensitive.
Generally, keywords of SQL are written in uppercase.

• Statements of SQL are dependent on text lines. We can


use a single SQL statement on one or multiple text line.

• Using the SQL statements, you can perform most of the


actions in a database.

• SQL depends on tuple relational calculus and relational


algebra.
What is SQL Process?
• When an SQL command is executing for any RDBMS,
then the system figure out the best way to carry
out the request and the SQL engine determines
that how to interpret the task.

• In the process, various components are included.


These components can be optimization Engine, Query
engine, Query dispatcher, classic, etc.

• All the non-SQL queries are handled by the classic


query engine, but SQL query engine won't
handle logical files.
What is SQL Process?
What is Advantages of SQL?
• High speed
• No coding needed
• Well defined standards
• Portability
• Interactive language
• Multiple data view
What is SQL Datatype?
• SQL Datatype is used to define the values that a
column can contain.
• Every column is required to have a name and data
type in the database table.
SQL Commands
• SQL commands are instructions. It is used to
communicate with the database. It is also used
to perform specific tasks, functions, and queries of
data.

• SQL can perform various tasks like:


 Create a table,
 Add data to tables,
 Drop the table,
 Modify the table,
 Set permission for users.
Types of SQL Commands
• There are five types of SQL commands: DDL,
DML, DCL, TCL, and DQL.
Data Definition Language (DDL)
• DDL changes the structure of the table like creating a
table, deleting a table, altering a table, etc.
• All the command of DDL are auto-committed that
means it permanently save all the changes in the
database.
• Here are some commands that come under DDL:
 CREATE
 ALTER
 DROP
 TRUNCATE
 RENAME
Data Definition Language (DDL)- CREATE
CREATE It is used to create a new table in the database.

Syntax:
CREATE TABLE TABLE_NAME (COLUMN 1_NAME DATATYPES, COLUMN
2_NAME DATATYPES[,.........]);

Example:
CREATE TABLE EMPLOYEE(Name VARCHAR2(20), Employee id INT, Email
VARCHA R2(100), DOB DATE);
Data Definition Language (DDL)- Drop,
RENAME
Drop: It is used to delete both the structure and record stored
in the table.
Syntax:
DROP TABLE table_name;
Example:
DROP TABLE EMPLOYEE;

Rename: It is used to rename a table in the database.


Syntax:
RENAME TABLE NAME TO NEW NAME;

Example:
RENAME EMP TO EMP2;
Data Definition Language (DDL)- ALTER
ALTER: It is used to alter the structure of the database. This change
could be either to modify the characteristics of an existing
attribute or probably to add a new attribute.

Syntax:
ALTER TABLE table_name ADD column_name COLUMN-definition;
ALTER TABLE MODIFY(COLUMN DEFINITION....);

Example:
ALTER TABLE STU_DETAILS ADD(ADDRESS VARCHAR2(20));
ALTER TABLE STU_DETAILS MODIFY (NAME VARCHAR2(20));
Data Definition Language (DDL)- TRUNCATE
TRUNCATE: It is used to delete all the rows from the table and free
the space containing the table.

Syntax:
TRUNCATE TABLE table_name;

Example:
TRUNCATE TABLE EMPLOYEE;
Data Manipulation Language
• DML commands are used to modify the database. It is
responsible for all form of CHANGES in the database.

• A data manipulation language (DML) is a


computer programming language used for
adding (inserting), deleting, and modifying
(updating) data in a database.

• It deal with date of object it provides three


commands
Here are some commands that come under DML:
 INSERT
 UPDATE
 DELETE
Data Manipulation Language - INSERT
INSERT: The INSERT statement is a SQL query. It is used to insert
data into the row of a table.
Syntax:
INSERT INTO TABLE_NAME (col1, col2, col3,....
col N)
VALUES (value1, value2, value3, .... valueN);

OR
INSERT INTO TABLE_NAME VALUES (value1, value2, value3, ....
valueN);

Example:
INSERT INTO Customers (customer_id, first_name,
last_name, age, country) VALUES (6, 'Alice', 'Brown', 30,
'Canada');
Data Manipulation Language - UPDATE
Update: This command is used to update or modify the value of a
column in the table.
Syntax:
UPDATE table_name SET [column_name1= value1,...column_n
ameN = valueN] [WHERE CONDITION]

Example:
UPDATE Customers
SET age = 29
WHERE customer_id = 5;
Data Manipulation Language - DELETE
DELETE
The SQL DELETE statement is used to delete row(s) from a
database table.

Syntax:
DELETE FROM table-name
For example,
DELETE FROM Customers
WHERE country = 'UAE';
Data Control Language
DCL commands are used to GRANT and TAKE BACK
authority from any database user.

Here are some commands that come under DCL:


 Grant

 Revoke
Data Control Language (DCL)
DCL commands include GRANT and REVOKE, which are used to control access
to the database.
i. GRANT
In SQL, the GRANT statement gives users access privileges to the database.
For example,
GRANT SELECT, UPDATE ON Customers TO user1;
This command grants SELECT and UPDATE permissions on
the Customers table to user1.

ii. REVOKE
In SQL, the REVOKE statement withdraws access privileges given by
the GRANT statement.
Let's look at an
example.
REVOKE SELECT ON Customers FROM user1;
Here, the SQL query revokes SELECT permission on the Customers table
from user1.
Data Control Language - Grant
GRANT: It is used to give user access privileges (permissions) to a
database.

Example:

GRANT SELECT, UPDATE ON MY_TABLE TO SOME_USER123;

REVOKE: It is used to take back permissions from the user.

Example:

REVOKE SELECT, UPDATE ON MY_TABLE FROM USER1, USER2;


SQL Operator
:SQL Arithmetic Operators
Operator Description
+ It adds the value of both operands.

- It is used to subtract the right-hand operand from the left-hand


operand.

It is used to multiply the value of both operands.


*
It is used to divide the left-hand operand by the right-
/
hand
operand.
It is used to divide the left-hand operand by the right-
%
hand
operand and returns reminder.
SQL Comparison Operators
Operator Description

= It checks if two operands values are equal or not, if the values are
queal then condition becomes true.

!= It checks if two operands values are equal or not, if values are not
equal, then condition becomes true.

<> It checks if two operands values are equal or not, if values are not
equal then condition becomes true.

It checks if the left operand value is greater than right operand


>
value,
if yes then condition becomes true.
It checks if the left operand value is less than right operand
<
value, if
yes then condition becomes true.
It checks if the left operand value is greater than or equal to the
>=
right
operand value, if yes then condition becomes true.
SQL Comparison Operators
Operator Description

<= It checks if the left operand value is less than or equal to the right
operand value, if yes then condition becomes true.

!< It checks if the left operand value is not less than the right operand
value, if yes then condition becomes true.

!> It checks if the left operand value is not greater than the right operand
value, if yes then condition becomes true.
SQL Logical Operators
Operator Description
All It compares a value to all values in another value set.

AND It allows the existence of multiple conditions in an SQL statement.

ANY It compares the values in the list according to the condition.

Between It is used to search for values that are within a set of values.

IN It compares a value to that specified list value.

NOT It reverses the meaning of any logical operator.

OR It combines multiple conditions in SQL statements.

EXIST It is used to search for the presence of a row in a specified table.

LIKE It compares a value to similar values using wildcard operator.


Example:
SQL> CREATE TABLE EMPLOYEE
( EMP_ID INT NOT NULL,
EMP_NAME VARCHAR (25) NOT NULL,
PHONE_NO INT NOT NULL,
ADDRESS CHAR (30),
PRIMARY KEY (ID)
);
• DESC EMPLOYEE;
• DELETE FROM table_name WHERE condition
• DROP TABLE "table_name";
• SELECT * FROM table_name;
• INSERT INTO TABLE_NAME VALUES (value1, value2, value 3, .... Value N);
• INSERT INTO TABLE_NAME[(col1, col2, col3,.... col N)] VALUES (value1,
value2, valu e 3, .... Value N);
• UPDATE table_name SET column_name = value WHERE condition;
Example:
• UPDATE table_name SET column_name = value1, column_name2 =
value WHERE condition;
• DELETE FROM table_name WHERE some_condition;
Views in SQL
• Views in SQL are considered as a virtual table. A view
also contains rows and columns.

• To create the view, we can select the fields from one


or more tables present in the database.

• A view can either have specific rows based on certain


condition or all the rows of a table.
Characteristics of SQL
• SQL is easy to learn.
• SQL is used to access data from relational database
management systems.
• SQL can execute queries against the database.
• SQL is used to describe the data.
• SQL is used to define the data in the database and manipulate
it when needed.
• SQL is used to create and drop the database and table.
• SQL is used to create a view, stored procedure, function in a
database.
• SQL allows users to set permissions on tables, procedures, and
views.
Application of SQL
SQL (Structured Query Language) is widely used in various applications across
industries. Here are some key applications:
1. Database Management

2. Data Retrieval & Manipulation

3. Data Analysis & Reporting

4. Web Development

5. Data Warehousing

6. Banking & Finance

7. Healthcare & Hospitals

8. E-commerce & Retail

9. Cloud Computing & Big Data

You might also like