SQL Syntax SELECT FROM TABLE WHERE ORDER BY GROUP BY HAVING
<< Previous - Introduction to SQL
SQL is a language to interact with RDBMS relational databases. SQL statement consists of SQL commands and user-defined names like table names, column names, and variables or data.
- The SQL statement is more readable since it has written in English-like language.
- SQL statement consists of SQL command or keyword and user-defined names (table name, column names, variable, etc.).
- Every SQL statement should end up with a semicolon(;).
- The SQL statement is not case-sensitive. We can use our variable in both lowercase and uppercase letter that will work out successfully. One good practice is to use uppercase for SQL commands or keywords and lowercase for user-defined words. That will help you to identify the different SQL keywords within the statement.
SQL query example
SELECT column1,column2,...columnN
FROM Table-name
WHERE [condition];
SQL Statement
- The statement consists of a verb, a keyword, table name, column name, many clauses, and expressions.
- Each statement begins with a verb that represent action
- CREATE, DELETE, UPDATE, INSERT are the example of the verbs in SQL statement.
- Both table names and column names can be the variable that can write in lowercase letters to differentiate from the keywords.
- Statement may contain one or more clauses. Clauses provide information about what the statement has to do.
- Each clause contains a table or column name, constant and conditional expression.
- The clauses also begin with a keyword such as FROM, WHERE, BETWEEN, HAVING, etc.
SQL Naming rules
SELECT column1,column2,...columnN
FROM Table-name
WHERE [condition];
In SQL statements, Names can be used for the table name, column name, and user name.
- Table Name should be short and more descriptive.
- Don't use the keyword as a table name or column name.
- Don't use special characters, except underscore( _ ) which is to link another word.
- User name may be the login name used to sign in to SQL console.
- Table name should be consistent and shouldn't conflict.
- If you want to access the table created by/for other users, you can use the qualified table name. The qualified table name refers to both the name of the table's owner and the name of the table, separated by period (. ).
Owner-name.Table-name
For example
Varun.Products
Varun refers to the owner name and Products refers to the Table name
- Column names must be unique in the single table.
- If you want to access two columns having the same name from different tables, you must use the qualified column name to prevent confusion. The qualified column name refers to both names of the table which contain the column and name of the column, separated by period ( . ).
table-name.Column-name
- If columns come from a table of the different users, we can use a qualified table name along with a qualified column name.
Owner-name.Table-name.Column-name
For example
Varun.Products.Price
<< Previous - Introduction to SQL