Different sub-languages In SQL

Different sub-languages In SQL

?? Hello, Friends!

I’m Dikshant Sharma, and I’m diving into the world of SQL! Today, I’ve been exploring the sub-languages of SQL and learning how they help manage and manipulate data. ???

It’s fascinating to see how different SQL sub-languages work together to make data handling more efficient and effective.

In SQL, different sub-languages or components are used to perform various tasks. Understanding these sub-languages can help you effectively interact with databases and manipulate data. Here’s a brief overview of the key SQL sub-languages:

1. Data Definition Language (DDL)

DDL is used to define and manage database structures. It includes commands that create, alter, and delete database objects like tables, indexes, and schemas.

  • CREATE: Used to create new database objects (e.g., tables, indexes)
  • Example: CREATE TABLE employees (id INT, name VARCHAR(100));
  • ALTER: Used to modify existing database objects
  • Example: ALTER TABLE employees ADD COLUMN hire_date DATE;
  • DROP: Used to delete database object
  • .Example: DROP TABLE employees;

2. Data Manipulation Language (DML)

DML is used to retrieve, insert, update, and delete data within tables.

  • SELECT: Used to retrieve data from one or more tables
  • Example: SELECT * FROM employees;
  • INSERT: Used to add new records to a table
  • Example: INSERT INTO employees (id, name) VALUES (1, 'John Doe');
  • UPDATE: Used to modify existing records
  • Example: UPDATE employees SET name = 'Jane Doe' WHERE id = 1;
  • DELETE: Used to remove records from a table
  • Example: DELETE FROM employees WHERE id = 1;

3. Data Control Language (DCL)

DCL is used to control access to data and manage permissions within the database.

  • GRANT: Used to give users specific privileges
  • Example: GRANT SELECT ON employees TO user1;
  • REVOKE: Used to remove specific privileges from users
  • Example: REVOKE SELECT ON employees FROM user1;

4. Data Query Language (DQL)

DQL is specifically used to query and retrieve data. While it’s often considered part of DML, it focuses solely on querying.

  • SELECT: As mentioned in DML, it’s used to query data, and its advanced features include filtering (WHERE), sorting (ORDER BY), and aggregating (GROUP BY).

5. Transaction Control Language (TCL)

TCL is used to manage transactions, ensuring data integrity and consistency.

  • COMMIT: Saves all changes made during the current transaction
  • Example: COMMIT;
  • ROLLBACK: Undoes changes made during the current transaction
  • Example: ROLLBACK;
  • SAVEPOINT: Sets a point within a transaction to which you can later roll back
  • Example: SAVEPOINT my_savepoint;

Understanding these sub-languages will help you effectively interact with databases, ensuring you can perform a wide range of operations and maintain data integrity.

要查看或添加评论,请登录

Dikshant Sharma的更多文章

社区洞察

其他会员也浏览了