SQL stands for structure query language, Which is used to communicate with database in form of queries.

In another, SQL stands for Structured Query Language. It is a programming language used for managing and manipulating relational databases. SQL provides a standardized way to interact with databases and perform various operations, such as querying data, inserting, updating, and deleting records, creating and modifying database structures, and controlling access to the database.

Syntax of SQL

SQL follows a set of rules and guidelines called syntax, which dictate how SQL statements should be structured. This tutorial provides a quick introduction to SQL by presenting the basic syntax for various SQL statements.

Every SQL statement begins with a keyword such as SELECT, INSERT, UPDATE, DELETE, ALTER, DROP, CREATE, USE, or SHOW. Each statement is concluded with a semicolon (;).

It’s important to note that SQL is case insensitive, meaning that SELECT and select are interpreted in the same way. However, when working with MySQL, table names are treated as case sensitive, so you should use the exact table names as they appear in the database.

Various Syntax in SQL

All the examples given in this tutorial have been tested with a MySQL server.

SQL SELECT Statement

SELECT column1, column2....columnN
FROM   table_name;

SQL DISTINCT Clause

SELECT DISTINCT column1, column2....columnN
FROM   table_name;

SQL WHERE Clause

SELECT column1, column2....columnN
FROM   table_name
WHERE  CONDITION;

SQL AND/OR Clause

SELECT column1, column2....columnN
FROM   table_name
WHERE  CONDITION-1 {AND|OR} CONDITION-2;

SQL IN Clause

SELECT column1, column2....columnN
FROM   table_name
WHERE  column_name IN (val-1, val-2,...val-N);

SQL BETWEEN Clause

SELECT column1, column2....columnN
FROM   table_name
WHERE  column_name BETWEEN val-1 AND val-2;

SQL LIKE Clause

SELECT column1, column2....columnN
FROM   table_name
WHERE  column_name LIKE { PATTERN };

SQL ORDER BY Clause

SELECT column1, column2....columnN
FROM   table_name
WHERE  CONDITION
ORDER BY column_name {ASC|DESC};

SQL GROUP BY Clause

SELECT SUM(column_name)
FROM   table_name
WHERE  CONDITION
GROUP BY column_name;

SQL COUNT Clause

SELECT COUNT(column_name)
FROM   table_name
WHERE  CONDITION;

SQL HAVING Clause

SELECT SUM(column_name)
FROM   table_name
WHERE  CONDITION
GROUP BY column_name
HAVING (arithematic function condition);

SQL CREATE TABLE Statement

CREATE TABLE table_name(
   column1 datatype,
   column2 datatype,
   column3 datatype,
   .....
   columnN datatype,
   PRIMARY KEY( one or more columns )
);

SQL DROP TABLE Statement

DROP TABLE table_name;

SQL CREATE INDEX Statement

CREATE UNIQUE INDEX index_name
ON table_name ( column1, column2,...columnN);

SQL DROP INDEX Statement

ALTER TABLE table_name
DROP INDEX index_name;

SQL DESC Statement

DESC table_name;

SQL TRUNCATE TABLE Statement

TRUNCATE TABLE table_name;

SQL ALTER TABLE Statement

ALTER TABLE table_name {ADD|DROP|MODIFY} column_name {data_ype};

SQL ALTER TABLE Statement (Rename)

ALTER TABLE table_name RENAME TO new_table_name;

SQL INSERT INTO Statement

INSERT INTO table_name( column1, column2....columnN)
VALUES ( value1, value2....valueN);

SQL UPDATE Statement

UPDATE table_name
SET column1 = value1, column2 = value2....columnN=valueN
[ WHERE  CONDITION ];

SQL DELETE Statement

DELETE FROM table_name
WHERE  {CONDITION};

SQL CREATE DATABASE Statement

CREATE DATABASE database_name;

SQL DROP DATABASE Statement

DROP DATABASE database_name;

SQL USE Statement

USE database_name;

SQL COMMIT Statement

COMMIT;

SQL ROLLBACK Statement

ROLLBACK;

Why SQL?

SQL (Structured Query Language) is a widely used programming language specifically designed for managing and manipulating relational databases. There are several reasons why SQL is popular and widely adopted:

  1. Simplicity: SQL has a straightforward and intuitive syntax, making it relatively easy to learn and use. Its declarative nature allows users to specify what data they want without needing to specify how to retrieve it, which simplifies the querying process.
  2. Standardization: SQL is an ANSI/ISO standard language, which means it is widely supported by database management systems (DBMS) across different vendors. This standardization ensures portability and interoperability, allowing users to switch between different DBMS without significant code changes.
  3. Powerful data manipulation: SQL provides a rich set of commands for data manipulation, such as inserting, updating, and deleting records. It also offers advanced query capabilities, including filtering, sorting, aggregating, and joining data from multiple tables. These features make it efficient and flexible for retrieving and manipulating data.
  4. Scalability and performance: SQL databases are designed to handle large amounts of structured data efficiently. They employ various optimization techniques, indexing mechanisms, and query execution plans to ensure fast and reliable performance, even with complex queries and massive datasets.
  5. Data integrity and security: SQL databases support features like transactions, constraints, and access control, ensuring data integrity and security. Transactions allow users to perform a series of database operations as a single unit, ensuring atomicity, consistency, isolation, and durability (ACID properties). Constraints enforce data integrity rules, while access control mechanisms protect data from unauthorized access.
  6. Integration with other technologies: SQL is often used in conjunction with other programming languages and technologies. It can be seamlessly integrated with applications, web servers, and frameworks, allowing developers to leverage the power of SQL for data storage and retrieval.

History of SQL

In 1970, computer scientist E.F. Codd published a paper titled “A Relational Model of Data for Large Shared Data Banks,” which greatly influenced the development of SQL.

IBM researchers Raymond Boyce and Donald Chamberlin were inspired by Codd’s work and subsequently created SEQUEL (Structured English Query Language) at the IBM Corporation’s San Jose Research laboratory in 1970. Later, in the late 1970s, Relational Software Inc., now known as Oracle Corporation, developed their own SQL implementation based on the concepts of Codd, Boyce, and Chamberlin. This SQL version focused on relational database management systems (RDBMS).

In June 1979, Oracle Corporation introduced Oracle V2, the first implementation of the SQL language, designed to run on VAX computers.

Related Posts

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Artificial Intelligence