What keyword is used to specify the tables and views used in a SELECT statement?

SQL KEYWORDS

The list of SQL keywords that are available in SQL.

1. ADD

ADD keyword is used to add a column to the existing table.

2. ADD CONSTRAINT

This keyword is used to create a constraint after a table is already created.

3. ALL

ALL, it returns TRUE, if all the mentioned sub-queries values meet the conditions.

4. ALTER TABLE

It is used to add, modify or delete columns in the table, along with the modification in the table, it can alter the various constraints in the table.

Syntax:

ALTER TABLE table_name
ADD column_name datatype;

Example:

ALTER TABLE CSE_BRANCH
ADD COLLEGE_ID varchar[255];

In the above example, the command is altering the table CSE_BRANCH, and a column COLLEGE_ID with the datatype varchar.

5. ALTER COLUMN

It changes the datatype of the specific column in the table.

Syntax:

ALTER TABLE table_name
ALTER COLUMN column_name datatype;

Example:

ALTER TABLE CSE_BRANCH
ALTER COLUMN YEAR_OF_GRADUATION year;

We are altering the datatype of the YEAR_OF_GRADUATION column of table CSE_BRANCH to year.

6. AND

AND keyword is used with the WHERE clause, and checks if both the conditions given in the WHERE clause are TRUE.

Syntax:

SELECT column_name FROM table_name
WHERE [condition] AND [condition];

Example:

SELECT * FROM CSE_BRANCH
WHERE YEAR_OF_GRADUATION = 2022 AND CGPA >= 8.0;

The above example is showing that we are selecting all the columns from table CSE_BRANCH whose CGPA is greater than 8.0, and their graduation is 2022.

7. ANY

It is used in where clause, and checks if any sub-query meets the condition then return TRUE.

Syntax:

SELECT column_name FROM table_name
WHERE ANY [sub_query];

Example:

SELECT * FROM CSE_BRANCH
WHERE CGPA = ANY [SELECT CGPA FROM CSE_BRANCH WHERE YEAR_OF_GRADUAION=2023];

8. AS

It is used as an alias. It is used to rename a column or a table.

Syntax:

SELECT column_name AS alias_name FROM table_name;

Example:

SELECT YEAR_OF_GRADUATION AS YEAR FROM CSE_BRANCH;

9. ASC

It helps us to sort the result in ascending order.

10. BETWEEN

The Between command is used to select the values within a specified range. The values can be numbers, text, or dates. The beginning and the ending value are inclusive[included] in between commands.

Syntax:

SELECT column_name FROM table_name
WHERE CGPA BETWEEN begin AND end;

Example:

SELECT * FROM CSE_BRANCH
WHERE CGPA BETWEEN 6.5 AND 7.5;

The above code will return a table in which CGPA lies between 6.5 and 7.5.

11. CASE

It is used to display different outputs based on different conditions.

Syntax:

CASE
    WHEN [condition] THEN "STATEMENT"
    ELSE "STATEMENT"

END

Example:

SELECT * FROM CSE_BRANCH
ORDER BY [CASE
            WHEN CGPA 

Chủ Đề