0 of 2 saved

Database Management Systems3 min read

Intoduction to SQL

Read this chapter, then pass a short check to open the next one.

Introduction to SQL (Structure Query Language). SQL is a query language used for storing, accessing and managing data in a relational database management system.

Introduction to SQL

SQL known as Structured Query Language is a database query language used for storing and managing data in Relational Database Management System. SQL was the first commercial language introduced for E.F Codd's Relational Model of Database. To perform SQL queries, you need to install any database, for example, MySql, Oracle, PostgreSQL, SQL Server, MS Access, etc. SQL is used to perform all types of data operations in RDBMS.

Characteristics of SQL

  • SQL is a database language, it is used for database creation, deletion, fetching rows, and modifying rows, etc.
  • SQL allows the user to describe, define the data in the database and manipulate the data when needed.
  • Using SQL, we can set different permissions on tables and views.
  • SQL statements are simple English-like statements that use SQL keywords with tuples and attributes.
  • SQL language is not case-sensitive and each SQL query ends with a semicolon (;). A semicolon separates SQL statements when written together in a database.

SQL Table

In SQL, we perform various operations on a table. SQL table consists of multiple records and is used for data storage. This table is represented in the form of columns and rows. Like in RDBMS, SQL table is known as a relation, a column is known as an attribute and a row is known as a tuple. A table has a specified number of columns but it can have any number of rows.

For example: In the below table, the table name is 'Books'. In this table, we have 5 columns (attributes) namely 'idLibrary', 'BookTitle', 'BookQuantity', 'Authot', 'BookPrice' and we have 4 rows (tuples) in the form of (1, 'The Chamber of Secrets', 10, 'JK Rowling', 2099).

SQL Table

SQL Commands

SQL defines the following ways to manipulate data stored in an RDBMS. These commands are used to perform various operations on a table. SQL Commands are broadly categorized into five languages:

SQL Commands

DDL: Data Definition Language

DDL changes the structure of the table by creating the table, altering the table, deleting a table, etc. All DDL commands are auto-committed. That means it saves all the changes permanently in the database.

Command Description
CREATE creates a new table or database
ALTER alters the structure of the table
TRUNCATE deletes records from the table
DROP deletes the structure and records from the table

DML: Data Manipulation Language

DML commands are used to manipulate the data stored in the table. These commands are not auto-committed i.e. changes are not permanent to the database, they can be rolled back.

Command Description
INSERT inserts a new row
UPDATE updates or modify the existing rows
DELETE deletes a row
MERGE merge two rows or two tables

TCL: Transaction Control Language

These commands are to keep a check on other commands and their effect on the database. These commands can annul changes made by other commands by rolling the data back to its original state. It can also make any temporary change permanent. TCL commands are only used with DML commands.

Command Description
COMMIT permanently saves all the transactions
ROLLBACK undo the changes that are not saved
SAVEPOINT saves data temporarily

DCL: Data Control Language

Data Control Language defines two commands to grant and take back authority from any database user.

Command Description
GRANT grants permission and privileges to a database
REVOKE takes back permission from the user

DQL: Data Query Language

Data Query Language is used to fetch data from tables based on conditions that we can easily apply.

Command Description
SELECT retrieves records from one or more table