SQL
SQL
SQL is a database language designed for the retrieval and management of data in a relational
database.
Five types of SQL queries are 1) Data Definition Language (DDL) 2) Data Manipulation
Language (DML) 3) Data Control Language(DCL) 4) Transaction Control Language(TCL) and,
5) Data Query Language (DQL)
Data Definition Language(DDL) helps you to define the database structure or schema.
Data Manipulation Language (DML) allows you to modify the database instance by inserting,
modifying, and deleting its data.
DCL (Data Control Language) includes commands like GRANT and REVOKE, which are
useful to give "rights & permissions."
Transaction control language or TCL commands deal with the transaction within the database.
Data Query Language (DQL) is used to fetch the data from the database.
Thus, SQL is a database language designed for the retrieval and management of data in a
relational database.
SQL is the standard language for database management. All the RDBMS systems like MySQL,
MS Access, Oracle, Sybase, Postgres, and SQL Server use SQL as their standard database
language. SQL programming language uses various commands for different operations.
It allows you to define the data in a database and manipulate that specific data.
With the help of SQL commands in DBMS, you can create and drop databases and
tables.
SQL offers you to use the function in a database, create a view, and stored procedure.
Types of SQL
Types of SQL
DDL
Data Definition Language helps you to define the database structure or schema. Let's learn about
DDL commands with syntax.
CREATE
Syntax:
For example:
DROP
Syntax
DROP TABLE ;
For example:
ALTER
Syntax:
TRUNCATE:
This command used to delete all the rows from the table and free the space containing the table.
Syntax:
Example:
Data Manipulation Language (DML) allows to modify the database instance by inserting,
modifying, and deleting its data. It is responsible for performing all types of data modification in
a database.
There are three basic constructs which allow database program and user to enter data and
information are:
INSERT
UPDATE
DELETE
INSERT:
This is a statement is a SQL query. This command is used to insert data into the row of a table.
Syntax:
Or
For example:
INSERT INTO students (RollNo, FIrstName, LastName) VALUES ('60', 'Tom', Erichsen');
UPDATE:
This command is used to update or modify the value of a column in the table.
Syntax:
For example:
UPDATE students
WHERE StudID = 3;
DELETE:
Syntax:
For example:
DCL
DCL (Data Control Language) includes commands like GRANT and REVOKE, which are
useful to give "rights & permissions." Other permission controls parameters of the database
system.
Grant
Revoke
Grant:
Syntax:
For example:
Syntax:
For example:
TCL
Transaction control language or TCL commands deal with the transaction within the database.
Commit
Syntax:
Commit;
For example:
COMMIT;
Rollback
Rollback command allows you to undo transactions that have not already been saved to the
database.
Syntax:
ROLLBACK;
Example:
SAVEPOINT
Syntax:
SAVEPOINT SAVEPOINT_NAME;
Example:
SAVEPOINT RollNo;
DQL
Data Query Language (DQL) is used to fetch the data from the database. It uses only one
command:
SELECT:
This command helps you to select the attribute based on the condition described by the WHERE
clause.
Syntax:
SELECT expressions
FROM TABLES
WHERE conditions;
For example:
SELECT FirstName
FROM Student
Oracle database provide built-in SQL data types also you can make user define types for letter
use as data types. Every database define a column data type for each and every tables.
SQL data types are two type scaler type or non scalar type. Scalar SQL data types haven't
internal components. It's like linear data types. Whereas non scalar SQL data types have internal
component to store multiple values and easily you can manipulate the data.
1. Numeric Datatypes
2. Character Datatypes
3. LONG and ROW Datatypes
4. ROWID Datatypes
5. Datetime Datatypes
6. Large Object Datatypes
Number Datatypes
Character Datatypes
Character Data type use to store alphabetic/alphanumeric, following are character data
types in Oracle SQL.