SQL Tutorial
SQL Database
SQL Table
SQL Select
SQL Order By
SQL Insert
SQL Update
SQL Delete
Difference
SQL Injection
SQL String Functions
Miscl
- SQL Formatter
- SQL group by
- SQL add/drop/update column operation
- SQL CAST Function
- SQL Comments
- SQL CONCAT Function
- CTE (Common Table Expression)SQL
- How to use distinct in SQL?
- Joining Three or More Tables in SQL
- What is Web SQL?
- How to create functions in SQL?
- How to run SQL Script?
- How to Delete Duplicate Rows in SQL?
- Nth Highest salary
- 12 Codd's Rules
- SQL EXCEPT
- Types of SQL JOIN
- Change datatype of column in SQL
- SQL Auto Increment
- SQL Like
- Commit and Rollback in SQL
- SQL Concatenate
- SQL get month from the date
- Savepoint in SQL
- SQL ORDER BY DATE
- TIME Datatype in SQL
- SQL BETWEEN
- CRUD Operations in SQL
- SQL INDEX
- Scalar Functions in SQL
- SET Operators in SQL
- Types of SQL Commands
- TCL Commands in SQL
- SQL Subquery
- SQL View
- Constraints in SQL
- Pattern Matching in SQL
- SQL Date Functions
- DDL Commands in SQL
- DML Commands in SQL
- SQL CASE
- SQL Inner Join
- SQL IN Operator
- Check Constraint in SQL
- SQL CLAUSES
- SQL LOGICAL OPERATORS
- Delete Column from Table
- Add Column in the Table
- Delete one row in SQL
- Change the Column Value
- How to Add Foreign Key in SQL
- Add a Primary Key
- Insert One or More rows
- How to Use LIKE in SQL
- Cursor in SQL
- Difference Between DROP and Truncate
- SQL Comparison Operators
- SQL COUNT WHERE
- SQL SELECT MIN
- SQL Stored Procedure
- SQL SELECT AVG
- SQL SELECT MAX
- SQL ADD COLUMN
- How to use Auto-Increment in SQL
- SQL Languages
- SQL Arithmetic Operators
- How to Use GROUP BY in SQL
- How to Use ORDER BY in SQL
- Trigger in SQL
- What is Race Condition
- SQL COUNT DISTINCT
PL/SQL Tutorial
Sql Interview Question
SQl Quiz
SQL Languages
SQL Languages are those languages that allow the database users to read, modify, delete and store data in the database systems.
Following are the four different types of languages or commands which are widely used in SQL queries:
- TCL (Transaction Control Language)
- DML (Data Manipulation Language)
- DCL (Data Control Language)
- DDL (Data Definition Language)
DDL (Data Definition Language)
Data Definition Languages allow users to create, modify, and destroy the schema of database objects.
We can enter the correct data in the database by applying the constraints in the DDL languages.
The DDL Languages or commands are categorized into five commands which are widely used in the SQL queries:
- CREATE DDL Command
- ALTER DDL Command
- DROP DDL Command
- TRUNCATE DDL Command
- RENAME DDL Command
Let's discuss each DDL command with syntax and examples.
CREATE Command
This DDL command allows us to create the new table, function, stored procedure, and other database objects.
Syntax of Create DDL Command to create a new table in the database:
Example of Create Command:
The following SQL query creates the new Mobile_Details table using CREATE DDL command:
(
Mobile_Number INT NOT NULL,
Mobile_Name Varchar(50),
Manufacturing_Year INT NOT NULL,
Mobile_Cost INT
);
ALTER Command
This DDL command allows us to modify the structure of database objects.
Syntax of Alter Command to modify the existing table:
Example of Alter Command:
The following SQL query adds the new column in the Mobile_Details table using ALTER DDL command:
DROP Command
This DDL command allows us to remove the table definition and data from the SQL systems.
Syntax of Drop Command to remove the existing table:
Example of Drop Command:
The following SQL query deletes the Mobile_Details table using the DROP DDL command:
DROP TABLE Mobile_Details;
TRUNCATE Command
This DDL command allows the database users to remove all the existing records from the table.
Syntax of Truncate Command to delete all records:
Example of Truncate Command:
The following SQL query deletes all the inserted records from the Mobile_Details table using the TRUNCATE DDL command:
RENAME Command
This DDL command allows the users to change the name of the existing table.
Syntax of RENAME Command for changing the table name:
Example of Rename Command:
The following SQL query changes the name of Mobile_Details table to Mobile_Records table using the RENAME DDL command:
DML (Data Manipulation Language)
Data Manipulation languages allow database users to change the existing data of the tables.
We can use this type of language when we want to access the record, insert the new record, update the record, and delete the existing values from the tables.
Following are the four DML Languages or commands used in the SQL queries:
- SELECT DML Command
- INSERT DML Command
- UPDATE DML Command
- DELETE DML Command
Let's discuss each DML command with syntax and examples.
SELECT Command
This DML command allows us to access the stored records from the tables. We can also use the condition in the SELECT command for accessing the particular rows.
Syntax of SELECT Command:
Example of SELECT Command:
The following SQL query shows the records of the Mobile_Records table using the SELECT DML command:
INSERT Command
This DML command allows the database users to insert the new record or rows in the tables.
Syntax of INSERT Command for inserting the single record:
Example of INSERT Command:
The following SQL query inserts the single record of mobile into the Mobile_Records table using the INSERT DML command:
UPDATE Command
This DML command allows the database users to change the existing record or rows in the tables.
Syntax of UPDATE Command for modifying the records:
Example of UPDATE Command:
The following SQL query updates the values of the Mobile_Records table using the UPDATE DML command:
DELETE Command
This DML command allows the database users to delete a particular record or row from the tables.
Syntax of DELETE Command for removing the records:
Example of DML DELETE Command:
The following SQL query deletes the values from the Mobile_Records table using the DELETE DML command:
DCL (Data Control Language)
Data Control Languages allow DBA to manage the rights and permissions on the data in the database.
Following are the two DCL Languages or commands used in the SQL queries:
Revoke DCL Command
Let's discuss the above two DCL commands one by one with syntax and examples.
GRANT Command
This DCL command allows the database administrator to give permissions to the user for retrieving the data.
Syntax of Grant DCL Command:
Example of Grant Command:
The following query grants the SELECT privilege on the Mobile_Records table:
REVOKE Command
This DCL command allows the database administrator to remove all the permissions applied by the GRANT DCL command.
Syntax of REVOKE DCL Command:
Example of REVOKE Command:
The following query removes the SELECT privilege from the Mobile_Records table:
TCL (Transaction Control Language)
Transaction Control languages maintain the SQL operations within the database. It also saves the changes made by the DML commands.
Following are the two TCL Languages or commands used in the SQL queries:
Rollback TCL Command
Let's discuss the above TCL commands one by one with syntax and examples.
COMMIT Command
This command allows the database users to save the operations in the database.
Syntax of Commit command:
Example of Commit Command:
The following statements delete the record from the Mobile_Record table and commit the changes in the database:
COMMIT;
Rollback Command
This command allows the database users to restore the transactions to that state which was last committed.
Syntax of Rollback command:
Example of Rollback Command:
The following statements delete the record from the Mobile_Record table and rollback the changes in the database:
ROLLBACK;