SQL stands for Structured Query Language. It is a standard language for managing relational databases. SQL is used to perform various tasks such as creating and modifying database schemas, inserting, updating, and deleting data in the database, and querying data from the database.
SQL is a declarative language, meaning that you specify what you want to achieve rather than specifying how to achieve it. This makes it a powerful and versatile tool for interacting with databases.
-
Creating Databases and Tables: SQL allows you to create databases and define the structure of tables within those databases, including specifying data types, constraints, and indexes.
-
Inserting, Updating, and Deleting Data: SQL provides commands for inserting new records into a table, updating existing records, and deleting records from a table.
-
Querying Data: SQL allows you to retrieve data from one or more tables using SELECT statements. You can filter, sort, and aggregate data as needed to extract the desired information.
-
Managing Permissions: SQL provides commands for granting and revoking permissions on database objects, allowing you to control who can access and manipulate the data in the database.
DDL commands are used to define, modify, and delete database objects such as databases, tables, views, indexes, etc. Common DDL commands include:
- CREATE: Used to create new database objects.
- ALTER: Used to modify existing database objects.
- DROP: Used to delete existing database objects.
- TRUNCATE: Used to remove all records from a table (but not the table structure itself).
DML commands are used to manipulate data stored in the database. Common DML commands include:
- SELECT: Used to retrieve data from one or more tables.
- INSERT: Used to add new records to a table.
- UPDATE: Used to modify existing records in a table.
- DELETE: Used to remove records from a table.
TCL commands are used to manage transactions within the database. A transaction is a sequence of one or more SQL operations that are treated as a single unit of work. Common TCL commands include:
- COMMIT: Used to permanently save changes made in a transaction.
- ROLLBACK: Used to undo changes made in a transaction.
- SAVEPOINT: Used to set a point within a transaction to which you can later roll back.
- SET TRANSACTION: Used to set properties for the current transaction.
DCL commands are used to control access to data stored in the database. Common DCL commands include:
- GRANT: Used to give specific privileges to database users.
- REVOKE: Used to revoke previously granted privileges from database users.