SQL Tutorial
SQL is a standard language designed to manage, retrieve, manipulate, and sort data in a relational database management system.
This tutorial will help you get started with SQL quickly. It will help you learn SQL from the basic to advanced topics step-by-step.
What is SQL
- SQL stands for Structured Query Language.
- SQL is used to communicate and manipulate databases.
- SQL is a standard database language specifically designed to retrieve, store, manipulate, sort, and manage data inside a relational database management system (RDBMS). SQL is originally based on relational algebra and tuple relational calculus.
- SQL is the most widely used database language. SQL is supported by popular database systems like MySQL, PostgreSQL, Oracle, SQL Server. However, some features of the SQL standard are implemented differently in various database systems.
- SQL became a standard of the ANSI in 1986, and of the ISO in 1987.
- SQL was initially developed by IBM in early 1970. The first version was initially called SEQUEL (Structured English Query Language) and changed after to SQL.
What can SQL do
There are different things that SQL can do:
- SQL can retrieve data from a database.
- SQL can execute queries against a database.
- SQL can insert records in a database.
- SQL can update (modify) records in a database.
- SQL can delete (remove) records in a database.
- SQL can create a database.
- SQL can create tables in a database.
- SQL can create views.
- SQL can create stored procedures, functions in a database.
- SQL can set permission on tables, views, and procedures.
The list is not exhausted. SQL can perform other database-related tasks.
What is a Database?
A database is an organized set of related data, generally stored in a computer system. This data is usually structured in a way that makes data easily accessible.
What is a Relational Database?
A Relational Database is a type of database based on the relational model of data. It uses a structure that allows to identify and access data in relation to another portion of data in the database. Relational Database organizes data into one or more tables of columns and rows.
Tables: Rows and Columns
Tables are uniquely identified by their names and are composed of columns and rows.
Columns are labeled with a descriptive name and have a specific data type. A column is a vertical entity in a table.
Rows contain the data or records for the columns. A record is a horizontal entity in a table.
Here is an example of a table called "Student":
student_id | name | age | city | dept_id |
---|---|---|---|---|
1 | John | 23 | Chicago | 3 |
2 | Mary | 22 | Boston | 4 |
3 | Wiliam | 21 | Los Angeles | 2 |
4 | Jennifer | 23 | Phoenix | 1 |
5 | Susan | 20 | Seattle | 2 |
In the above table, there are four columns (student_id, name, age, city)
The "name" and "city" columns store string data types, while "student_id" and "age" store integer data types. The columns and data type makes the schema of this table. The table also has five records or rows in it.
RDBMS
RDBMS stands for Relational Database Management System.
RDBMS is a software that interacts with the end-users. It allows to create, query, update and administer a relational database.
Most RDBMS uses SQL language to communicate with the database.
SQL is a standard
SQL is an ANSI/ISO standard. However, most of the database systems have their own additional exclusive extensions that are usually only used on their system.
All the database systems support at least the major commands (like SELECT, INSERT, UPDATE, DELETE, WHERE) in a similar way.