EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials SQL Tutorial SQL Syntax
 

SQL Syntax

Updated March 16, 2023

SQL Syntax

 

 

Introduction to SQL Syntax

SQL syntax is nothing but how SQL statements work correctly while executing on the database server. We are assigning the table name of each table. Tables are made up of data records. SQL is adhered to by a distinct rule known as All SQL statements begin with one of these keywords, like the show, create, delete, alter, insert, update use, and they all end with a semicolon (;).

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Overview

We know that one database contains more than one table in single database. The most important thing to remember about SQL is SQL is not case sensitive; SELECT and select have the same meaning in SQL statements. Table names in MySQL, on the other hand, differ. Many people are unaware that SQL was initially intended to be typed into a console, and the results are displayed on a screen. As a result, the syntax is similar to that found in English. However, this never occurred because the operator risked causing significant issues typing on the query. For example, consider typing ‘DELETE Customer WHERE Id = 101, but we have pressing enter after customer, which causes an SQL syntax error.

The below example shows it is not case sensitive. In the first example below, we have used all the query words in lower case letters; executing this query will return the result without error. Also, In the below second example, we have used all the query words in upper case letters; after executing this query, it will return the result without error because SQL syntax is not case sensitive.

Code:

# select * from sql_test;
# SELECT * FROM SQL_TEST;

Output:

SQL Syntax 1

Various SQL Syntax

Below is the various syntax which is used in the database at the time of executing the specified query as follows:

1. Syntax of SQL select statement

Select statement of SQL syntax will vary per the SQL query we used on the DB server.

Syntax:

Select name_of_column1, name_of_column2, ….., name_of_columnN from name_of_table;

2. SQL distinct clause

Below is the SQL distinct clause as follows.

Syntax:

Select distinct name_of_column1, name_of_column2, ….., name_of_columnN from name_of_table where condition;

3. SQL where clause

Below is the SQL where clause as follows.

Syntax:

Select name_of_column1, name_of_column2, ….., name_of_columnN from name_of_table where condition;

4. SQL AND/OR clause

Below is the SQL AND / OR clause as follows.

Syntax:

Select name_of_column1, name_of_column2, ….., name_of_columnN from name_of_table where condition1 {AND / OR} condition1;

5. SQL IN clause

Below is the SQL IN clause as follows.

Syntax:

Select name_of_column1, name_of_column2, ….., name_of_columnN from name_of_table where name_of_column IN (Val1, Val2, …., ValN);

6. SQL between clause

Below is the SQL between clauses as follows.

Syntax:

Select name_of_column1, name_of_column2, ….., name_of_columnN from name_of_table where name_of_column between Val1 AND val2;

7. SQL-like clause

Below is the SQL-like clause as follows.

Syntax:

Select name_of_column1, name_of_column2, ….., name_of_columnN from name_of_table where name_of_column like {pattern};

8. SQL count clause

Below is the SQL count clause as follows.

Syntax:

Select count(name_of_column) from name_of_table where condition;

9. SQL drop database statement

Below is the SQL syntax of the drop database statement as follows.

Syntax:

Drop database name_of_database;

10. SQL commit, rollback, and use database statement

Below is the syntax of commit, rollback, and use database statement.

Syntax:

Commit;
Rollback
\c name_of_database (in postgresql); use name_of_database; (in MySQL)

11. SQL delete statement

Below is the syntax of the SQL delete statement as follows.

Syntax:

Delete from name_of_table where condition;

12. SQL insert statement

Below is the syntax of the SQL insert statement as follows.

Syntax:

Insert into name_of_table (col1, col2, …, colN) values (val1, val2, …, valN);

SQL Syntax Table

If suppose we need to perform any operation on any database, we must write predefined syntax of a query defined by the specified database. This syntax is distinct in each database, a distinct set of rules and guidelines that are not case-sensitive. Of course, we can write our query in uppercase and lowercase letters, but writing our SQL syntax in the uppercase letter will improve the query readability. It will tell the database which type of operations we perform on structured data and what information we want to retrieve.

Below is the SQL create table statement as follows.

Syntax:

Create table name_of_table (name_of_column1 name_of_datatype,
name_of_column2 name_of_datatype, ….
name_of_columnN name_of_datatype,
primary key (name of one or more column));

Below is the syntax of the drop table and drop database statement.

Syntax:

Drop table name_of_table;

Below is the syntax for updating table records.

Syntax:

Update name_of_table set name_of_column1 = val1, name_of_column2 = val2, …, name_of_columnN = valN [condition of where];

Below syntax shows an altered table to change the table’s name as follows.

Syntax:

Alter table name_of_table to new_table_name;

Below syntax shows altered table statement as follows.

Syntax:

Alter table name_of_table {DROP | MODIFY | ADD} name_of_column {data_type};

Examples of SQL Syntax

Different examples are mentioned below:

Example #1 – Create table

Code:

Create table test (id int, name varchar(10));

Output:

SQL Syntax 2

Example #2 – Create database

Code:

Create database sql_test;

Output:

database

Example #3 – Insert statement

Code:

Insert into test values (101, ‘ABC’);

Output:

Insert statement

Example #4 – Update statement

Code:

Update test set id = 111 where id = 101 and name = ‘ABC’;

Output:

Update

Example #5 – Delete statement

Code:

Delete from test where id = 111 and name = ‘ABC’;

Output:

Delete

Example #6 – Alter statement

Code:

Alter table test rename to test1;
Alter table test1 drop name;

Output:

SQL Syntax 7

Example #7 – Select statement

Code:

Select * from test1;
select * from test1 where id = 101;
select id from test1;

Output:

Select

Example #8 – Drop table and database

Code:

Drop table test1;
drop database pre_stmt;

Output:

SQL Syntax 9

Conclusion

Text lines are required for SQL statements and syntax. SQL statements are straightforward, easy to use, and understand. They are similar to plain English but have a different syntax. It is nothing but how the SQL statement works correctly while executing on the database server.

Recommended Articles

This is a guide to SQL Syntax. Here we discuss the introduction, overview, various SQL syntax, and examples for better understanding. You may also have a look at the following articles to learn more –

  1. SQL ORDER BY DESC
  2. SQL EXECUTE
  3. SQL EXCLUDE
  4. MySQL InnoDB Cluster

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

🚀 Limited Time Offer! - ENROLL NOW