Introduction of SQL Keywords, Or List of SQL Reserved Words

Summary: You will learn in this article, Introduction of SQL Keywords, Or List of SQL Reserved Words. These SQL keywords reference contains the reserved words in SQL. basically, these SQL Keywords are part of the SQL Server T-SQL grammar. I hope you will enjoy SQL Keywords article.

Introduction To SQL Keywords

The SQL keywords are the reserved words it is used for the purpose of performing various operations in the database. There are several keywords in SQL and as SQL is case insensitive, it doesn’t matter if we use for example SELECT or select.

  • SQL Server basically, uses reserved keywords for database operations.
  • Therefore, these keywords in SQL are part of the SQL Server T-SQL grammar.
  • SQL Server has claimed current & future SQL reserved words.
  • Keywords are often used as identifiers by putting them between [ ] (square brackets).

List of SQL Keywords

1. CREATE 2. PRIMARY KEY 3. INSERT 4. SELECT
5. FROM 6. ALTER 7. ADD 8. DISTINCT
9. UPDATE 10. SET 11. DELETE 12. TRUNCATE
13. AS 14. ORDER BY 15. ASC 16. DESC
17. BETWEEN 18. WHERE 19. AND 20. OR
21. NOT 22. LIMIT 23. IS NULL 24. DROP
25. DROP COLUMN 26. DROP DATABASE 27. DROP TABLE 28. GROUP BY
29. HAVING 30. IN 31. JOIN 32. UNION
33. UNION ALL 34. EXISTS 35. LIKE 36. CASE

Explanation of SQL Keywords

Furthermore, these SQL keywords can be used as explained in the given below examples for several operations.

1). CREATE

The CREATE Keyword in SQL is used for the purpose of creating a database, table, views, and index. We can create the table CUSTOMERS as below.

2). PRIMARY KEY

This keyword uniquely identifies every one of the records. A SQL Server Database can be created with the usage of CREATE DATABASE statement as given below:

A View in SQL can be created by the utilization of CREATE VIEW as given below:

3). INSERT

The SQL INSERT Keyword is utilized for the purpose of inserting the rows of data into a table. Furthermore, we can insert the below rows to the already created CUSTOMERS table by using the given below queries.

Therefore, as per the above-given statements will insert the rows into the table “CUSTOMERS”. after that, we can see the result by using a simple SQL SELECT statement as given below.


SQL Keywords

4). SELECT

This SELECT keyword is used to select the data from the database or table. The ‘*’ is utilized in the select statement to select all the columns in a table.

The result of the given above query will display the column CUSTOMERS_NAME from the CUSTOMERS table as below.
SQL Keywords-SELECT Example

5). FROM

The keyword in SQL is used to point to the table from which the data is selected or deleted.

6). ALTER

The Keyword ALTER in SQL is used to modify the columns in tables. Furthermore, the ALTER COLUMN statement modifies the data type of a column & the ALTER TABLE modifies the columns by adding or deleting them. We can modify the columns of the CUSTOMERS table as given below by adding a new column “PHONE”.

ALTER Clause Example
This query statement above will add the new column “PHONE” with values for all the rows as null. Furthermore, the given above statement uses another SQL keyword ‘ADD’.

7). ADD

This keyword is used to add a column to the existing or present table.

8). DISTINCT

The keyword SQL DISTINCT is used to select distinct values. Furthermore, we can use SQL SELECT DISTINCT to select only the distinct values from a table.

Therefore, let us add a duplicate value for the state Ghaziabad as below:

Therefore, the CUSTOMERS table has now the below rows

SQL DISTINCT Clause Example
Now we will see the distinct values for the column CITY by utilizing the below query:

SQL DISTINCT Example

9). UPDATE

This keyword in SQL can be used in an SQL statement to update the existing rows in a table.

sql update Clause Example
The CUSTOMERS_ID with value 117 is updated with a new city Lucknow.

10). SET

This Keyword in SQL is used basically to specify the column or values to be updated.

11). DELETE

SQL Delete Keyword is used for the purpose of deleting the existing rows from a table.

The given above query will display the below as the row with CUSTOMERS_NAME as Lalit is deleted from the result set.
SQL DELETE Clause Example
Furthermore, while using the SQL DELETE keyword, if we don’t use the WHERE clause, then all the records will be deleted from the table.

The given above query will delete all the records of the CUSTOMERS table.

12). TRUNCATE

This keyword is used to delete the data in a table, however, it doesn’t delete the structure of the table.

The given above query only deletes the data but the structure of the table remains. therefore there’s no need to re-create the table.

13). AS

The Keyword AS in SQL is used as an alias to rename the column or table.

The given above statement will create the alias for the columns CUST_ID and NAME as below:
SQL AS Clause Example

14). ORDER BY

The ORDER BY keyword is used to sort the result in descending or ascending order. Furthermore, this keyword sorts the result by default in ascending order.

15). ASC

It’s used for sorting the data returned by the SQL query in ascending order.

SQL ASC Clause Example
The given above query will select all the columns from the CUSTOMERS table and it sorts the data by the NAME column in ascending order.

16). DESC

This SQL DESC keyword is to sort the result set in descending order.

SQL DESC Example
The given above SQL query will sort all the selected fields of the table with the descending order of CUSTOMERS_NAME.

17). BETWEEN

This SQL BETWEEN keyword is utilized to select values within a given range. Furthermore, the below query uses the BETWEEN keyword to select the CUSTOMERS_ID and CUSTOMERS_NAME within a given range of values for the CUSTOMERS_ID.

The given above SQL query will give the below result
SQL BETWEEN Example

18). WHERE

This SQL WHERE keyword is used to filter the result set so that only the values satisfying the condition are included

The given above SQL query selects all the values from the CUSTOMERS table for which the CITY is Lucknow.
WHERE Clause Example

19). AND

This SQL AND keyword are used along with the WHERE clause to select the rows for which both the conditions are true.

The given above SQL query will give the result as below
AND Clause Example
But suppose that if one of the conditions isn’t satisfied, then the query will not return any result as CITY in the below query.

20). OR

This SQL OR Keyword is used with the SQL WHERE clause to include the rows in the result set in case of either condition is true.
The given below SQL statement will select the fields from the CUSTOMERS table if the CITY is Lucknow or Noida.

SQL OR Example
Furthermore, in the case of the SQL OR keyword, we can see from the above result that in the case any of the given conditions are true, then that gets included in the result set.

21). NOT

The SQL NOT keyword is used with an SQLWHERE clause to include the rows in the result set where a condition is not true. We can use the SQL NOT keyword in the given below SQL query to not include the rows from the CITY Lucknow as below.

The SQL query will return the rows with the other cities excluding Lucknow in the result set as below:
NOT Clause Example

22). LIMIT

This SQL LIMIT keyword retrieves the records from the table in order to limit them based on the limit value.

The given above SQL query will select the records from the table CUSTOMERS but it will display only the three(3) rows of data from the table.

23). IS NULL

The SQL keyword IS NULL is used for the pur[pose of checking for NULL values.
The given below SQL query will show all the records for which the PHONE column has NULL values.

IS NOT NULL
This is utilized for the purpose of searching the NOT NULL values.

As column CITY has no null values, so, the given above SQL query will show the below result.
IS NULL Clause Example

24). DROP

The SQL DROP keyword can be used to delete a database, table, view, column, index, etc.

25). DROP COLUMN

We can delete an existing column in a table by using a SQL DROP COLUMN along with an ALTER statement. Furthermore, let us delete column PHONE by using the given below SQL query.

DROP COLUMN Clause Example
We can see that in the above result, the PHONE column is dropped.

26). DROP DATABASE

A database in SQL can be deleted by using the SQL DROP DATABASE statement.

27). DROP TABLE

Therefore, a table in SQL can be deleted by using a SQL DROP TABLE statement.

We can delete the table CUSTOMERS by using the SQL DROP TABLE keyword as given below.
But here, we need to be careful while using SQL DROP TABLE as it will remove the table definition along with all the data and indexes, etc.

28). GROUP BY

This is used along with the SQL aggregate functions like COUNT, MAX, MIN, AVG, SUM, etc., and groups the result set. The given below query will group the CUSTOMER_ID according to the various CITY.

29). HAVING

This Having keyword in SQL is used with aggregate functions and GROUP BY instead of the SQL WHERE clause to filter the values of a result set.

The given above SQL query will filter the result set by displaying only those values that satisfy the condition given within the HAVING clause
having Clause Example
The above result set shows that the values for which the count of the customer_id is more than 1.

30). IN

The SQL IN keyword is used within a SQL WHERE clause to specify more than 1 value or in other words, we can say that it can be used instead of the usage of multiple OR keywords in a query.

The given below SQL query will select the records for the City Kanpur, Lucknow, and Ghaziabad by the use of the SQL IN keyword.

IN Clause Example
The given above result set shows the usage of IN SQL keyword which selects the records only for the CITY specified within the IN clause.

31). JOIN

The SQL JOIN keyword is used to combine the rows between two or more tables with related columns among the tables. Furthermore, the SQL JOIN can be INNER, LEFT, RIGHT, OUTER JOIN, etc.
Furthermore, lets us take another table ‘CUSTOMERS_ORDER’ as an example.
JOIN Clause Example

We can perform an SQL inner join of the CUSTOMERS and CUSTOMERS_ORDER tables as below.

The given above SQL query will join the two tables CUSTOMERS and CUSTOMERS_ORDER on the columns CUSTOMERS_ID and ID and display only the values which are present in both the tables.
JOIN Keyword
The above result screenshot shows the matching records for customers_id 111 and 161. which are common in both the tables. But the other customers_ids are excluded as they are not present in the CUSTOMERS_ORDER table. Therefore, similarly, the other SQL JOINS can be performed.

32). UNION

The SQL UNION keyword is utilized in SQL to combine the distinct values of two or more select statements.

The given above SQL query will show the below result.
UNION Clause Example

33). UNION ALL

This keyword in SQL combines two or more select statements but it allows duplicate values.

The given above SQL query will show the below result.
UNION ALL Clause Example
The given above result shows that SQL UNION ALL allows duplicate values which would not be present in the case of UNION.

34). EXISTS

Furthermore, the keyword EXISTS checks if a certain record exists in a sub-query

The given above SQL query will return true as the sub-query returns the below values.
EXISTS Clause Example

35). LIKE

This SQL keyword is used for the purpose of searching along with a WHERE clause for a particular pattern. Furthermore, Wildcard % is used to search for a pattern.

In the given below SQL query let us search for a pattern ‘ad’ which occurs in the column ‘CUSTOMERS_NAME’.

36). CASE

This SQL keyword is used to display different outputs according to different conditions.

A few other keywords are DEFAULT used to provide a default value for a column, Furthermore, The SQL UNIQUE is used to ensure all the values in a column are unique, etc.

Related Question And Answer (FAQs)

What are keywords in SQL?

Answer: The keywords in SQL are those that are reserved words that are used for the purpose of performing various operations in the database. Therefore, there are many keywords in SQL and as SQL is case insensitive, it doesn’t matter if we use for example SELECT or select.

How do you use keywords in SQL query?

Answer: The keyword here is reserved word in SQL. suppose that if you ARE using SQL Server, then you can just simply wrap the square brackets around the column or table name. Furthermore, I even have additionally sweet-faced this issue. and also the resolution for this is to put [Column_Name] like this in the query.

What are database keywords?

Keywords, also commonly known as search terms, are the words that you just enter into the database search boxes. Furthermore, they represent the main concepts or most ideas of your research topic and are the words used in everyday life to describe and explain the topic.

Is a reserved SQL keyword?

Reserved words are SQL keywords and other different symbols that have special meanings when they are processed by the Relational Engine. Therefore, the Reserved words aren’t recommended for use as a database, table, column, variable, or other object names.

Conclusion

You have learned in this article, SQL Keywords, the various keywords in SQL basically provide flexibility in designing a database, tables, etc. They provide the designer with several features which become most useful while making any changes after the design is completed. I hope you will enjoy it!