0% found this document useful (0 votes)
384 views4 pages

SQL Syntax Overview and Guidelines

This document provides an overview of SQL syntax and statements. It explains that SQL statements begin with keywords like SELECT, INSERT, UPDATE, DELETE and end with a semicolon. The most common statements are described, including SELECT, WHERE, ORDER BY, GROUP BY, INSERT, UPDATE, DELETE and more. Examples are given for each statement type to illustrate the basic SQL syntax.

Uploaded by

Dipak Gite
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
384 views4 pages

SQL Syntax Overview and Guidelines

This document provides an overview of SQL syntax and statements. It explains that SQL statements begin with keywords like SELECT, INSERT, UPDATE, DELETE and end with a semicolon. The most common statements are described, including SELECT, WHERE, ORDER BY, GROUP BY, INSERT, UPDATE, DELETE and more. Examples are given for each statement type to illustrate the basic SQL syntax.

Uploaded by

Dipak Gite
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
  • Introduction to SQL Syntax
  • SQL DISTINCT Clause
  • SQL WHERE Clause
  • SQL SELECT Statement
  • SQL GROUP BY Clause
  • SQL COUNT Clause
  • SQL LIKE Clause
  • SQL BETWEEN Clause
  • SQL IN Clause
  • SQL HAVING Clause
  • SQL ORDER BY Clause
  • SQL ALTER TABLE Statement
  • SQL DROP TABLE Statement
  • SQL CREATE TABLE Statement
  • SQL CREATE INDEX Statement
  • SQL DROP INDEX Statement
  • SQL TRUNCATE TABLE Statement
  • SQL ALTER TABLE Statement (Rename)
  • SQL DROP DATABASE Statement
  • SQL ROLLBACK Statement
  • SQL DELETE Statement
  • SQL COMMIT Statement
  • SQL INSERT INTO Statement
  • SQL UPDATE Statement
  • SQL CREATE DATABASE Statement

8/8/2021 SQL - Syntax - Tutorialspoint

SQL - Syntax

SQL is followed by a unique set of rules and guidelines called Syntax. This tutorial gives you a
quick start with SQL by listing all the basic SQL Syntax.

All the SQL statements start with any of the keywords like SELECT, INSERT, UPDATE,
DELETE, ALTER, DROP, CREATE, USE, SHOW and all the statements end with a semicolon
(;).
The most important point to be noted here is that SQL is case insensitive, which means
SELECT and select have same meaning in SQL statements. Whereas, MySQL makes
difference in table names. So, if you are working with MySQL, then you need to give table
names as they exist 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;

[Link] 1/4
8/8/2021 SQL - Syntax - Tutorialspoint

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

[Link] 2/4
8/8/2021 SQL - Syntax - Tutorialspoint

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};

[Link] 3/4
8/8/2021 SQL - Syntax - Tutorialspoint

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;

[Link] 4/4

Common questions

Powered by AI

The ALTER TABLE statement modifies the structure of an existing table by adding, dropping, or modifying columns, changing table options, and renaming tables. Risks associated with using ALTER TABLE include potential data loss (e.g., when dropping columns) and performance impacts on large tables, as structural changes can require substantial processing time and affect existing applications relying on the table's current schema .

The SQL BETWEEN clause is used to filter results within a specific range of values. The benefits of using BETWEEN include simplifying the syntax for range comparisons and improving readability by reducing reliance on complex logical operators. However, its limitations include potential performance issues when indexing on large datasets is poor and the need for careful consideration of boundary values to ensure query accuracy .

The SQL ORDER BY clause is used to sort the resulting data set returned by a query in either ascending (ASC) or descending (DESC) order based on one or more columns. This clause significantly enhances the readability and usability of query results by allowing the data to be viewed in a meaningful order, facilitating data analysis and report generation .

The SQL DISTINCT clause is used to remove duplicate rows from the results of a SELECT statement, ensuring that each returned row is unique based on the specified columns. It impacts the query results by potentially reducing the result set size and is useful in situations where unique values are required for analytical purposes or when ensuring data accuracy and integrity is critical .

SQL is generally case insensitive, meaning that keywords such as SELECT and select have the same meaning. However, MySQL distinguishes between different cases for table names, so it is important to refer to table names as they exist in the database .

The HAVING clause allows for filtering results after aggregating data using the GROUP BY clause. Unlike WHERE, which filters rows before aggregation, HAVING applies conditions to aggregated columns. It is used in scenarios where filtering is required on summarized data, such as finding groups with specific aggregate characteristics, making it valuable in scenarios involving complex data reporting .

The TRUNCATE TABLE statement is used to remove all rows from a table without deleting the table itself, which can be more efficient and faster as it typically bypasses logging and foreign key constraints. DROP TABLE, on the other hand, deletes the table along with its data and associated metadata. TRUNCATE is useful for retaining table structure for reuse, whereas DROP is used when the table is no longer needed .

The SQL GROUP BY clause groups rows that have the same values in specified columns into aggregated data. This is essential for applying aggregate functions, such as SUM, AVG, COUNT, MAX, and MIN, which calculate summary values for each group. GROUP BY allows a more organized structure for reporting and analysis, enabling more efficient data aggregation and summarization .

The SQL COUNT function calculates the number of rows that match a specified condition. It is typically used to determine the size of result sets, validate the existence of data, or calculate the number of items in a group. Uses include generating statistical summaries, such as total order counts, and ensuring data quality by checking for expected data volumes .

The SQL WHERE clause is used to filter records by specifying conditions that must be satisfied for the records to be included in the results. It allows users to specify criteria through expressions, combining conditions using logical operators such as AND and OR, enabling precise data retrieval based on specified conditions .

8/8/2021
SQL - Syntax - Tutorialspoint
https://www.tutorialspoint.com/sql/sql-syntax.htm
1/4
SQL - Syntax
SQL - Syntax
SQL is
8/8/2021
SQL - Syntax - Tutorialspoint
https://www.tutorialspoint.com/sql/sql-syntax.htm
2/4
SQL IN Clause
SQL IN Clause
SELE
8/8/2021
SQL - Syntax - Tutorialspoint
https://www.tutorialspoint.com/sql/sql-syntax.htm
3/4
WHERE  CONDITION
WHERE  CONDITIO
8/8/2021
SQL - Syntax - Tutorialspoint
https://www.tutorialspoint.com/sql/sql-syntax.htm
4/4
SQL ALTER TABLE Statement (Renam

You might also like