> For the complete documentation index, see [llms.txt](https://gyansetu-sql.gitbook.io/sql-programming/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gyansetu-sql.gitbook.io/sql-programming/master.md).

# Introduction to SQL

### What is SQL?

* Structured Query Language is a standard Database language which is used to create, maintain and retrieve the relational database.
* SQL became a standard of the American National Standards Institute (ANSI) in 1986, and of the International Organization for Standardization (ISO) in 1987

### What Can SQL do?

* SQL can execute queries against a database
* SQL can retrieve data from a database
* SQL can insert records in a database
* SQL can update records in a database
* SQL can delete records from a database
* SQL can create new databases
* SQL can create new tables in a database
* SQL can create stored procedures in a database
* SQL can create views in a database
* SQL can set permissions on tables, procedures, and views

### SQL is a Standard - BUT....

Although SQL is an ANSI/ISO standard, there are different versions of the SQL language.

However, to be compliant with the ANSI standard, they all support at least the major commands (such as SELECT, UPDATE, DELETE, INSERT, WHERE) in a similar manner.

> &#x20;**Note:** Most of the SQL database programs also have their own proprietary extensions in addition to the SQL standard!

### RDBMS

RDBMS stands for Relational Database Management System.

RDBMS is the basis for SQL, and for all modern database systems such as MS SQL Server, IBM DB2, Oracle, MySQL, and Microsoft Access.

The data in RDBMS is stored in database objects called tables. A table is a collection of related data entries and it consists of columns and rows.

Below table shows the relational database with only one relation called **STUDENT** which stores **ROLL\_NO**, **NAME**, **ADDRESS**, **PHONE** and **AGE** of students.

**STUDENT**

| **ROLL\_NO** | **NAME** | **ADDRESS** | **PHONE**  | **AGE** |
| ------------ | -------- | ----------- | ---------- | ------- |
| 1            | RAM      | DELHI       | 9455123451 | 18      |
| 2            | RAMESH   | GURGAON     | 9652431543 | 18      |
| 3            | SUJIT    | ROHTAK      | 9156253131 | 20      |
| 4            | SURESH   | DELHI       | 9156768971 | 18      |

These are some important terminologies that are used in terms of relation.

**Attribute:** Attributes are the properties that define a relation. e.g.; **ROLL\_NO**, **NAME** etc.

**Tuple:** Each row in the relation is known as tuple. The above relation contains 4 tuples, one of which is shown as:

| 1 | RAM | DELHI | 9455123451 | 18 |
| - | --- | ----- | ---------- | -- |

**Degree:** The number of attributes in the relation is known as degree of the relation. The **STUDENT** relation defined above has degree 5.

**Cardinality:** The number of tuples in a relation is known as cardinality. The **STUDENT** relation defined above has cardinality 4.

**Column:** Column represents the set of values for a particular attribute. The column **ROLL\_NO** is extracted from relation STUDENT.

| **ROLL\_NO** |
| ------------ |
| 1            |
| 2            |
| 3            |
| 4            |

### Types Of SQL Commands

The queries to deal with relational database can be categorized as:

**Data Definition Language (DDL):** It is used to define the structure of the database. e.g; CREATE TABLE, ADD COLUMN, DROP COLUMN and so on.

**Data Manipulation Language (DML):** It is used to manipulate data in the relations. e.g.; INSERT, DELETE, UPDATE and so on.

**Data Query Language (DQL):** It is used to extract the data from the relations. e.g.; SELECT

**Data Control Language** (**DCL**) is used to control access to data stored in a database. e.g.; GRANT, REVOKE&#x20;

**Transaction Control Language(TCL)** commands are used to manage transactions in the database. e.g.; COMMIT, ROLLBACK, SAVEPOINT.
