Lecture-2: Structured Query Language (Basics)
Lecture-2: Structured Query Language (Basics)
Delivered By:
M r. S h u b h a m S h u k l a
WHAT IS SQL?
SQL is Structured Query Language, which is a computer language for storing,
manipulating and retrieving data stored in a relational database.
Why SQL?
SQL is widely popular because it offers the following advantages:
• Allows users to access data in the relational database management systems.
• Allows users to describe the data.
• Allows users to define the data in a 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 Process
• When you are executing an SQL command for any RDBMS, the system
determines the best way to carry out your request and SQL engine figures out
how to interpret the task. There are various components included in this
process.
These components are –
Query Dispatcher
Optimization Engines
Classic Query Engine
SQL Query Engine, etc.
• A classic query engine handles all the non-SQL queries, but a SQL query
engine won't handle logical files.
• Following is a simple diagram showing the SQL Architecture:
SQL CONSTRAINTS
• NOT NULL Constraint: Ensures that a column cannot have a NULL value.
• DEFAULT Constraint: Provides a default value for a column when none is
specified.
• UNIQUE Constraint: Ensures that all the values in a column are different.
• PRIMARY Key: Uniquely identifies each row/record in a database table.
• FOREIGN Key: Uniquely identifies a row/record in any another database
table.
• CHECK Constraint: The CHECK constraint ensures that all values in a
column satisfy certain conditions.
• INDEX: Used to create and retrieve data from the database very quickly.
DATA INTEGRITY
• The following categories of data integrity exist with each RDBMS:
Entity Integrity: There are no duplicate rows in a table.
Domain Integrity: Enforces valid entries for a given column by
restricting the type, the format, or the range of values.
Referential integrity: Rows cannot be deleted, which are used by other
records.
User-Defined Integrity: Enforces some specific business rules that do
not fall into entity, domain or referential integrity.
SQL - DATA TYPES
Character Datatypes: