Rules to write SQL commands with some important SQL commands

Rules for SQL commands

1. SQL  commands can be written on multiple line.

2. Clauses are generally used to separate lines to build accuracy through it is not necessary.

3. Tabulation (Index) can be used.

4. Command words cannot divide over the lines.

5. SQL commands are not case sensitive.

6. SQL commands is enrolled with SQL prompt. The SQL prompt, perform as a command line buffer.

7. Execution takes place when the statementis specified by a semi-colon(;).

8. Only one statement can be present at any time within the buffer and it can be run in multiple ways.
     Place a semicolon (;) at the end of the last clause.
     Place a semicolon (;) forward slash / on the last line in the buffer.
     Place a forward slash at the SQL prompt.
     Point a RUN command at the SQL prompt.

Some important SQL commands

These commands are very useful for the user to understand the structure of the table.

illustrate <table name>;

Example :- 

​illustrate <students>;

SELECT statements

 

1. SELECT command provides the query proficiency. It retrieves information and useful data from the table.

2. By executing SELECT command current information in the table will reflect on the screen.

3. The SELECT statement has three basic components that is:

SELECT, FROM and WHERE

4. This command extract useful information and stored in a table.

Syntax :-  SELECT column_list
                 FROM    table_list
                 WHERE search_scale

5. SELECT, FROM and WHERE  are keywords.

         The SELECT  keyword is used to specify a column that you want to
         retrieve from the column-list.

         The FROM clause is used to specify the table from which the column is
         to be  retrieved (restore).

         The WHERE  clause is used to limit the rows and returned by your query.

SELECT * FROM table_name;

 The (*) asterisk is used to fetch all the columns from the table.

Example :- Table students

Id
name
dob
class
section
address
1781Diva12-09-199810A34K park street, Noida 
1790karan02-02-20018CL 134 dreamworld sector12, Noida
1765Vicky08-11-199910B23 / 89 jain vihar, Greater noida
1796Harsh28--3-19997A78/90 B wings sector17, Greater noida
SELECT id,name,class FROM students WHERE class=10;

This query will display three columns of the students table that is id, name, and the class whose class is 10. 

Id
name
class
1781Diva10
1765Vicky10

 

Example :-

SELECT * FROM students WHERE section='A';

This query will display five columns of the students table that is id, name, dob(date-of-birth), class, section and address whose section is A. 

Id
name
dob
class
section
address
1781Diva12-09-199810A34K park street, Noida 
1796Harsh28--3-19997A78/90 B wings sector17, Greater noida

 

Use of WHERE clause 

The WHERE clause is used to meet the certain condition from the table.It must follow the FROM clause. It compares the value in the columns, literal values, arithmetic expression and other functions.

It expects three elements that is:
A column name
A comparison operator such as =, >, <, != etc .
A column name, constant or list of values.

Syntax :-select-list

SELECT[ALL/DISTINCT] [TOPn] [PERCENT] [WITH TIES]]

[INTO  new-Table]

[FROM  table-Source]

[WHERE  search_Condition]

[GROUP  By [ALL] Group_by_expression

[WITH  {CUBE ROLLUP}]]

[HAVING  search_Condition]

[ORDER BY  {column_name [Asc /DESC]} [,.........n]]

[COMPUTE  {Column_Name [Asc /DESC]} [,.........n]]

[COMPUTE  {{ AVG | COUNT | MAX | MIN | SUM } (expression) } [,....n]

[FOR BROWSE] [OPTION (query_hint[,.....n])]


Keywords: