Database is a collection of interrelated data.
DBMS (Database Management System) is software used to create, manage, and organize databases.
-> RDBMS (Relational Database Management System) - is a DBMS based on the concept of tables (also called relations).
-> Data is organized into tables (also known as relations) with rows (records) and columns (attributes).
Eg - MySQL, PostgreSQL, Oracle etc.
SQL is Structured Query Language - used to store, manipulate and retrieve data from RDBMS.
It is not a database, it is a language used to interact with database)
SQL is a language used to perform CRUD operations in Relational DB, while MySQL is a RDBMS that uses SQL.
In SQL, data types define the kind of data that can be stored in a column or variable.
CHAR,VARCHAR,BLOB,INT,TINYINT,BIGINT,BIT,FLOAT,DOUBLE,BOOLEAN,DATE,TIME,YEAR.
1. DQL (Data Query Language) : Used to retrieve data from databases. (SELECT)
2. DDL (Data Definition Language) : Used to create, alter, and delete database objects like tables, indexes, etc. (CREATE, DROP, ALTER, RENAME, TRUNCATE)
3. DML (Data Manipulation Language): Used to modify the database. (INSERT, UPDATE, DELETE)
4. DCL (Data Control Language): Used to grant & revoke permissions. (GRANT, REVOKE)
5. TCL (Transaction Control Language): Used to manage transactions. (COMMIT, ROLLBACK, START TRANSACTIONS, SAVEPOINT)
Data Definition Language (DDL) is a subset of SQL (Structured Query Language) responsible for defining and managing the structure of databases and their objects.
DDL commands enable you to create, modify, and delete database objects like tables, indexes, constraints, and more.
DQL (Data Query Language) is a subset of SQL focused on retrieving data from databases.
The SELECT statement is the foundation of DQL and allows us to extract specific columns from a table.
Data Manipulation Language (DML) in SQL encompasses commands that manipulate data within a database.
DML allows you to insert, update, and delete records, ensuring the accuracy and currency of your data.
Data Control Language focuses on the management of access rights, permissions, and security-related aspects of a database system.
DCL commands are used to control who can access the data, modify the data, or perform administrative tasks within a database.
DCL is an important aspect of database security, ensuring that data remains protected and only authorised users have the necessary privileges.
The GRANT command is used to provide specific privileges or permissions to users or Privileges can include the ability to perform various actions on tables, views, procedures, and other database objects.
The REVOKE command is used to remove or revoke specific privileges or permissions that have been previously granted to users or roles.
Transaction Control Language (TCL) deals with the management of transactions within a database.
TCL commands are used to control the initiation, execution, and termination of transactions, which are sequences of one or more SQL statements that are executed as a single unit of work.
Transactions ensure data consistency, integrity, and reliability in a database by grouping related operations together and either committing or rolling back changes based on the success or failure of those operations.
It makes all the changes applied to the database since the last COMMIT or ROLLBACK command permanent.
Once a COMMIT is executed, the transaction is considered successful, and the changes are made permanent.
The ROLLBACK command is used to undo changes made during a transaction. It reverts all the changes applied to the database since the transaction began.
ROLLBACK is typically used when an error occurs during the execution of a transaction, ensuring that the database remains in a consistent state.
The SAVEPOINT command creates a named point within a transaction, allowing you to set a point to which you can later ROLLBACK if needed.
SAVEPOINTs are useful when you want to undo part of a transaction while preserving other changes.