You are on page 1of 8

INTRODUCTION TO SQL

Structured Query Language (SQL) is a database language used for formulating


statements that are processed by a database server. This sentence contains three
important concepts: database, database server, and database language.

A database consists of some collection of persistent data that is used by the


application systems of some given enterprise, and that is managed by a database
management system.

Card index files do not, therefore, constitute a database. On the other hand, the large
files of banks, insurance companies, telephone companies, or the state transport
department can be considered databases. These databases contain data about
addresses, account balances, car registration plates, weights of vehicles, and so on.
For example, the company you work for probably has its own computers, and these
are used to store salary-related data.

The Relational Model


SQL is based on a formal and mathematical theory. This theory, which consists of a set
of concepts and definitions, is called the relational model. The relational model was
defined by E. F. Codd in 1970, when he was employed by IBM. He introduced the
relational model in the almost legendary article entitled “A Relational Model of Data
for Large Shared Data Banks”; see [CODD70]. This relational model provides a
theoretical basis for database languages. It consists of a small number of simple
concepts for recording data in a database, together with a number of operators to
manipulate the data. These concepts and operators are principally borrowed from set
theory and predicate logic. Later, in 1979, Codd presented his ideas for an improved
version of the model.
According to ANSI (American National Standards Institute), it is the standard language
for relational database management systems.
Why SQL?
• Allows users to access data in relational database management systems
• Allows users to describe the data
• Allows users to define the data in database and manipulate that data
• Allows to embed within other languages using SQL modules, libraries & pre-
compilers
• Allows users to create and drop databases and tables
• Allows users to create view, stored procedure, functions in a database
• Allows users to set permissions on tables, procedures and views

SQL: History
1970
Dr. Edgar F. "Ted" Codd of IBM is known as the father of relational databases. He
described a relational model for databases.

1974
Structured Query Language appeared.

1978
System/R was released by IBM working on Codd’s ideas.

1986
IBM developed the first prototype of relational database and standardized by ANSI.
The first relational database was released by Relational Software and its later
becoming Oracle.
Table : The entire storage structure Employee Table
is called a table
Column : A column is a vertical
entity in a table that contains all
information associated with a
specific field in a table
Row : A row is a horizontal entity
in an table. It represents all the
data of a particular employee
Field : A table consists of several
records, each record can be broken
into smaller entities called fields
Null value : It is a field is the table
that is blank. It is different from a
zero value or a field that contains

The standard SQL commands to interact with relational databases are


➢ CREATE
➢ SELECT
➢ INSERT
➢ UPDATE
➢ DELETE
➢ DROP
These commands can be classified into groups based on their nature.
CONSTRAINT
Constraints are part of a database schema definition.
A constraint is usually associated with a table and is created with a CREATE
CONSTRAINT or CREATE ASSERTION SQL statement.
They define certain properties that data in a database must comply with. They can
apply to a column, a whole table, more than one table or an entire schema. A reliable
database system ensures that constraints hold at all times (except possibly inside a
transaction, for so called deferred constraints).
“Schema" refers to the organization of data as a blueprint of how the database is
constructed. The formal definition of a database schema is a set of formulas
(sentences) called integrity constraints imposed on a database.

Common Constraints in SQL

NOT NULL Ensures that the column does not have a null value

DEFAULT
Provides a default value for a column when none is specified
CONSTRAINT

UNIQUE
Ensures that all the value in the column is different
CONSTRAINT

PRIMARY
Uniquely identified each row records in the database table
KEY

FOREIGN
Uniquely identified each row records in another database table
KEY

CHECK
Ensures that all the value in a column satisfy certain condition
CONSTRAINT

INDEX It is used to create and retrieve data quickly. Eg: Index of a book
DATABASE LANGUAGES:

DDL - Data Definition Language:


DML - Data Manipulation Language:

DCL - Data Control Language:


TCL - Transaction Control Language:

Relationship between tables


For Syntax Reference, please refer to the Cheatsheet PDF provided

END OF NOTES

You might also like