Introduction to SQL

What is SQL?
SQL (Structured Query Language) is a database computer language used to communicate with and retrieve data from relational databases. It allows users to store, manipulate, update, and retrieve data efficiently. SQL is widely used with popular database systems such as Oracle, MySQL, SQL Server, and DB2.
SQL is also referred to as:
● Structured Query Language
● Syntax Query Language
● Sequential Query Language
It is mainly used to interact with structured databases where data is stored in tables consisting of rows and columns.
Basic SQL Query Structure
A simple SQL query follows this format:
|
1 2 3 |
SELECT <column_name> FROM <table_name> WHERE <condition>; |
This structure helps users retrieve specific data from a database based on given conditions.
History of SQL
● 1970: Dr. Edgar F. “Ted” Codd of IBM introduced the relational database model. He is known as the father of relational databases.
● 1974: Structured Query Language (SQL) appeared.
● 1978: IBM developed a prototype relational database named System/R.
● 1986: SQL was standardized by ANSI (American National Standards Institute).
Advantages of SQL
● SQL is an English-like language, making it easy to learn and understand.
● It is an ANSI standard language, approved by IT professionals and software vendors.
● SQL is platform-independent and works on different operating systems.
● It is a non-procedural language, meaning users specify what data is needed rather than how to get it.
● It supports high-performance data retrieval and manipulation.
Data and Database Concepts
● Data: A collection of raw facts such as numbers, characters, or symbols.
● Information: Processed data that has meaning.
● Database: A collection of organized data.
● DBMS (Database Management System): Software that manages databases and controls data access.
DBMS: Advantages and Disadvantages
Advantages:
● Data is well structured
● High search performance
● High data security
Disadvantages:
● Relationship between multiple tables is not supported
● Data redundancy is high
● NULL values are not supported
● To overcome these limitations, RDBMS was introduced.
RDBMS (Relational Database Management System)
RDBMS is a database management system based on the relational model introduced by Dr. E. F. Codd. In RDBMS, data is stored in multiple related tables.
Dr. E. F. Codd proposed 12 rules, known as Codd’s Rules, which define a true relational database system.
Note:
To qualify as an RDBMS, a DBMS must follow at least 6 Codd rules, including 3 mandatory rules.
Codd’s Rules (Overview)
● Information Rule (Mandatory)
● Systematic Treatment of NULL Values
● Comprehensive Data Sub-language Rule
● Non-Subversion Rule
● Rule of Guaranteed Access
● Logical Data Independence
● Physical Data Independence
● Data Distribution Rule
● Data Description Rule
● Data Integrity Rule
● View Update Rule
● High-Level Insert, Update, and Delete Rule
Mandatory Codd Rules (Must Follow)
1. Information Rule (Mandatory)
All data must be stored in tables (rows and columns).
Example: Student details must be stored in a table, not in files or pointers.
2. Systematic Treatment of NULL Values (Mandatory)
RDBMS must support NULL values.
Key Points:
● NULL ≠ 0
● NULL ≠ space
● NULL ≠ NULL
Example: If a phone number is unknown, it should be stored as NULL.
3. Rule of Guaranteed Access (Mandatory)
Each data value must be accessible using:
● Table name
● Primary key
● Column name
This avoids ambiguity and ensures direct access to data.
Important Codd Rules (Any 3 Required)
4. RDBMS must support a complete data language with:
● Data definition
● Data manipulation
● Data control
(SQL satisfies this rule.)
5. Non-Subversion Rule
Low-level operations must not bypass high-level security and integrity rules.
6. Logical Data Independence
Changes in table structure should not affect user applications.
7. Physical Data Independence
Changes in physical storage (hardware, memory) should not affect users.
8. Data Distribution Rule
Data distribution across multiple locations should be transparent to users.
9. Data Description Rule
Metadata must be stored in tables and be accessible using SQL.
Example: DESC table_name;
10. Data Integrity Rule
Integrity constraints ensure data accuracy:
● PRIMARY KEY
● FOREIGN KEY
● UNIQUE
● NOT NULL
● CHECK
11. View Update Rule
Operations performed on a view must reflect in the base table.
12. High-Level Insert, Update, Delete Rule
RDBMS must support insert, update, and delete operations at a high level for multiple users.
SQL Sub-Languages
SQL is divided into five sub-languages:
Language |
Full Form |
Purpose |
Commands |
DDL |
Data Definition Language |
Defines database structure |
CREATE, ALTER, DROP, TRUNCATE, RENAME |
DML |
Data Manipulation Language |
Modifies data |
INSERT, UPDATE, DELETE |
DQL |
Data Query Language |
Retrieves data |
SELECT |
DCL |
Data Control Language |
Controls access |
GRANT, REVOKE |
TCL |
Transaction Control Language |
Manages transactions |
COMMIT, ROLLBACK, SAVEPOINT |
Dual Table
The DUAL table is a special dynamic table that contains one column and one row. It is accessible to all users and is commonly used to display expressions or system values.
Conclusion
SQL is a powerful, flexible, and easy-to-learn language used for managing relational databases. With its standardized syntax, platform independence, and strong data handling capabilities, SQL plays a crucial role in modern database systems and applications. Understanding SQL and RDBMS concepts is essential for anyone pursuing a career in databases or software development.
Author : Bharath Kumar
LinkedIn : https://www.linkedin.com/in/bharath-kumar-5a48b9360
Thank you for giving your valuable time to read the above information. Please click here to subscribe for further updates.
KTExperts is always active on social media platforms.
Facebook : https://www.facebook.com/ktexperts
LinkedIn : https://www.linkedin.com/company/ktexperts/
Twitter : https://twitter.com/ktexpertsadmin
YouTube : https://www.youtube.com/c/ktexperts
Instagram : https://www.instagram.com/knowledgesharingplatform
Note: Please test scripts in Non Prod before trying in Production.

