PL-SQL
Oracle PL/SQL Stored Procedure & Functions with Examples
In this tutorial, you are going to see the detailed description on how to create and execute the...
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. We will learn about the like DCL, TCL, DQL, DDL and DML commands in SQL with examples.
In this SQL commands in DBMS tutorial, you will learn:
Here, are important reasons for using SQL
Here, are important landmarks from the history of SQL:
Here are five types of widely used SQL queries.
Types of SQL
Let see each of them in detail:
Data Definition Language helps you to define the database structure or schema. Let's learn about DDL commands with syntax.
Five types of DDL commands in SQL are:
CREATE statements is used to define the database structure schema:
Syntax:
CREATE TABLE TABLE_NAME (COLUMN_NAME DATATYPES[,....]);
For example:
Create database university; Create table students; Create view for_students;
Drops commands remove tables and databases from RDBMS.
Syntax
DROP TABLE ;
For example:
Drop object_type object_name; Drop database university; Drop table student;
Alters command allows you to alter the structure of the database.
Syntax:
To add a new column in the table
ALTER TABLE table_name ADD column_name COLUMN-definition;
To modify an existing column in the table:
ALTER TABLE MODIFY(COLUMN DEFINITION....);
For example:
Alter table gtupapers add subject varchar;
This command used to delete all the rows from the table and free the space containing the table.
Syntax:
TRUNCATE TABLE table_name;
Example:
TRUNCATE table students;
Data Manipulation Language (DML) allows you 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:
Here are some important DML commands in SQL:
This is a statement is a SQL query. This command 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);
For example:
INSERT INTO students (RollNo, FIrstName, LastName) VALUES ('60', 'Tom', Erichsen');
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_nameN = valueN] [WHERE CONDITION]
For example:
UPDATE students SET FirstName = 'Jhon', LastName= 'Wick' WHERE StudID = 3;
This command is used to remove one or more rows from a table.
Syntax:
DELETE FROM table_name [WHERE condition];
For example:
DELETE FROM students WHERE FirstName = 'Jhon';
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.
Commands that come under DCL:
This command is use to give user access privileges to a database.
Syntax:
GRANT SELECT, UPDATE ON MY_TABLE TO SOME_USER, ANOTHER_USER;
For example:
GRANT SELECT ON Users TO'Tom'@'localhost;
It is useful to back permissions from the user.
Syntax:
REVOKE privilege_nameON object_nameFROM {user_name |PUBLIC |role_name}For example:
REVOKE SELECT, UPDATE ON student FROM BCA, MCA;
Transaction control language or TCL commands deal with the transaction within the database.
This command is used to save all the transactions to the database.
Syntax:
Commit;
For example:
DELETE FROM Students WHERE RollNo =25; COMMIT;
Rollback command allows you to undo transactions that have not already been saved to the database.
Syntax:
ROLLBACK;
Example:
DELETE FROM Students WHERE RollNo =25;
This command helps you to sets a savepoint within a transaction.
Syntax:
SAVEPOINT SAVEPOINT_NAME;
Example:
SAVEPOINT RollNo;
Data Query Language (DQL) is used to fetch the data from the database. It uses only one command:
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 WHERE RollNo > 15;
In this tutorial, you are going to see the detailed description on how to create and execute the...
What is Database Design? Database Design is a collection of processes that facilitate the...
What is the LIMIT keyword? The limit keyword is used to limit the number of rows returned in a...
$20.20 $9.99 for today 4.5 (125 ratings) Key Highlights of SQL Tutorial PDF 220+ pages eBook...
What is Package in Oracle? PL/SQL package is a logical grouping of a related subprogram...
What is the DELETE Query? MySQL DELETE command is used to delete rows that are no longer required from...