What keyword is used to specify the tables and views used in a SELECT statement?
SQL KEYWORDS Show
The list of SQL keywords that are available in SQL. 1. ADDADD keyword is used to add a column to the existing table. 2. ADD CONSTRAINTThis keyword is used to create a constraint after a table is already created. 3. ALLALL, it returns TRUE, if all the mentioned sub-queries values meet the conditions. 4. ALTER TABLEIt 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:
Example:
In the above example, the command is altering the table CSE_BRANCH, and a column COLLEGE_ID with the datatype varchar. 5. ALTER COLUMNIt changes the datatype of the specific column in the table. Syntax:
Example:
We are altering the datatype of the YEAR_OF_GRADUATION column of table CSE_BRANCH to year. 6. ANDAND keyword is used with the WHERE clause, and checks if both the conditions given in the WHERE clause are TRUE. Syntax:
Example:
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. ANYIt is used in where clause, and checks if any sub-query meets the condition then return TRUE. Syntax:
Example:
8. ASIt is used as an alias. It is used to rename a column or a table. Syntax:
Example:
9. ASCIt helps us to sort the result in ascending order. 10. BETWEENThe 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:
Example:
The above code will return a table in which CGPA lies between 6.5 and 7.5. 11. CASEIt is used to display different outputs based on different conditions. Syntax:
Example:
The above SQL query will return a table which is ordered by roll number if CGPA is less than 4, otherwise the table will be ordered by CGPA. Check out this article on the CASE Statement to learn more about CASE in SQL. 12. CHECKThis constraint limits the value that can be placed in a column. 13. CREATEThis CREATE keyword is used to create a database, table, views, and index. Syntax:
Example:
The above is used to create a table. 14. DEFAULTDefault constraint provides a default value for a column. Example:
The above code is used to create a table in which the default value of the branch field is set to ECEECE. 15. DELETEThe DELETE statement is used to delete the existing records from the table. Example:
The above SQL code will delete all rows in a table CSECSE_BRANCHBRANCH whose CGPA is less than 6.56.5. 16. DESCDESC command is used to sort the data in descending order. The following SQL code will sort the required table in descending order of CGPA. Example:
17. DISTINCTDISTINCT is used to select only different values from the table. Example:
The above code selects all the different values from the BATCH column in the CSE_BRANCH table. 18. DROPThe DROP statement is used to delete a column in the mentioned table. Syntax: The following SQL code states that we are dropping a column BATCH from the table CSE_BRANCH. Example:
19. EXECEXEC command is used to execute a stored procedure. Syntax: The following SQL code tells us we are executing a stored procedure, i.e., SelectPlacedStudents. Example:
20. EXISTSThe EXISTS commands test whether there exists any record in the sub-query. If the records are present in the sub-query, then, EXISTS will return True. Otherwise, it returns False. Syntax:
Example:
In the above SQL code, if our sub_query returns True, then only our main query will work, else it will return an empty table. 21. FOREIGN KEYForeign Key constraint is a key that is used to link two tables together. It is the field(s) in one table that refers to the PRIMARY KEY in another table. We can declare Foreign Key at the time of the creation of the table. Syntax:
Example:
In the above SQL code, a table named ITIT_BRANCHBRANCH has been created, with roll number as the primary key and email as its foreign key. 22. FROMFROM command is used to specify the table on which we need to operate. Example:
The above command selects all the available records in the table CSECSE_BRANCHBRANCH. 23. GROUP BYThe GROUP BY keyword is used to group the result set, and it is used with the aggregate functions like COUNT, MAX, MIN, SUM, AVG etc. Syntax:
Example:
24. HAVINGHAVING statement is similar to WHERE statement. The difference between HAVING and WHERE is that in the HAVING clause, we can use aggregate functions, whereas in the WHERE clause, we can't use aggregate functions. Syntax:
Example:
In the above code, we select two columns from the CSECSE_BRANCHBRANCH table and group them on the roll_numner to see how many batches have a total number of students = 30. 25. INThe IN constraint allows us to specify multiple values in the WHERE clause. Syntax:
Example:
The above code will select all the records whose batch is A1, A2, A3, or A4. 26. INDEXINDEX is used to create or delete the indexes in the table. Indexes help us to retrieve data from the database very fast. It helps us to speed up the performance of our queries/searching. Syntax:
The following SQL code creates an index indexCGPAindexCGPA on the column CGPACGPA of table ECEBRANCHECE_BRANCH. Example:
27. INSERTINSERT command is used to insert the data into the table.
Syntax:
Example:
In the above example, we insert values in the table CSECSE_BRANCHBRANCH.
Syntax:
Example:
In the above code, we are just copying all the data of CSECSEBRANCHBRANCH data to the table ALLALLBRANCHESBRANCHES table. 28. JOINJOIN command is used to JOIN TABLES. There are different JOINS available in SQL:
29. LIKEIt is used with the WHERE clause to search for a specified pattern in that mentioned column. % - It is used to represent multiple characters. _ - It is used to represent a single character. Syntax:
The following SQL code will return a table where the roll number starts from 19. Example:
30. LIMITLIMIT is used to specify the number of returned records. Syntax: Example:
The above code will show only 100 records due to the limit constraint that we have applied. 31. NOTThis command is used with the WHERE clause to only include those that record where a condition is not true. Syntax:
Example:
The above code will return a table with no A1 batch students record. 32. ORThis OR command is used with the WHERE clause, which results in whether to include record(s) on a given condition. Syntax:
Example:
In the above example, the query will return the table that contains only batch = A1 and A2. 33. ORDER BYORDER BY command is used to sort the result by ascending or descending order. But by default ORDER BY sorts the result in ascending order. Example:
34. PRIMARY KEYThe PRIMARY KEY constraint uniquely identifies each record in a table. A table can have only one primary key. Syntax:
Example:
The above SQL code has created a table named ITIT_BRANCHBRANCH , with roll number as the primary key. 35. PROCEDUREPROCEDURE is used to create a store procedure. A STORED PROCEDURE is a SQL code that can be reused again. Syntax:
Example:
36. SELECTSELECT statement is used to select the data from a database, and that data is returned is stored in a table. Syntax:
Example:
37. TOPTOP command is used with SELECT. It will select the mentioned number of records from the table. Syntax:
Example:
It will return a table in which it will have the first 10 records. 38. TRUNCATEPreviously we have studied the DROP command in which we have deleted our table, but this time we will see the TRUNCATE statement which will not delete the table, it will delete the data inside the table. Syntax:
Example:
39. UNIONThis UNION statement will combine the result of two or more queries. It will combine only distinct records. Syntax: Example:
40. UNION ALLThe UNION statement allows only distinct values, whereas the UNION ALL also allows duplicate values. Syntax: Example:
Check out this article to learn more about UNION and UNION ALL. 41. UNIQUEThe UNIQUE constraint ensures that all the values in a column are unique. Example:
42. WHEREThe WHERE clause filters the table, which includes records that fulfill a specific condition. Syntax:
The following SQL code will return a table where the roll number will start from 20. Example:
43. UPDATEUPDATE command is used to update the existing records in a table. Example:
The following code will update the table CSECSE_BRANCHBRANCH and set the BRANCHBRANCH as CSECSE. 44. IS NULLThis command is used to check whether any record is empty or not. Example:
It will return a table in which all the roll numbers are NULL. Which keyword is used by SQL to specify the source table or tables of a database query?The FROM clause specifies one or more tables to be queried. Use a comma and space between table names when specifying multiple tables. The WHERE clause selects only the rows in which the specified column contains the specified value. The value is enclosed in single quotes (for example, WHERE last_name='Vader' ).
Which part of a SELECT statement specifies the tables FROM which?The FROM clause, which indicates the table(s) to retrieve data from. The FROM clause can include optional JOIN subclauses to specify the rules for joining tables. The WHERE clause includes a comparison predicate, which restricts the rows returned by the query.
Which SQL keyword must be used in a Make table query?CREATE TABLE is the keyword to tell the database to create a table. table_name is the unique name that is used for the table. The brackets that are next to the table name contains the list of columns. The list contains the column name and the data type that can be stored in the respective columns.
What is the keyword for SELECT?SQL Keywords. |