When it comes to syntax, SQL is not that tough and quite easy if you compare it with other languages.
Some basic syntax rules a SQL newbie should know are as follows:-
- SQL queries are not case-sensitive which means that ‘SELECT’ is similar to ‘select’.
- All the queries start with SQL commands and end with a semicolon(;).
- String values should be enclosed within single quotes (‘ ‘).
- Date values must be enclosed in single quotes (‘ ‘) and should be in the format ‘YYYY-MM-DD’.
- SQL syntax rules depend on the type of Database you are using.
SELECT & FROM
The SELECT command is used to specify which columns you want to retrieve from the table(s). FROM keyword specify the Database and Table Name.
SYNTAX: SELECT COL_1, COL_2 FROM demo_tab ;
Sometimes we use stars(*) with the SELECT command to retrieve all the columns of the table.
SYNTAX: SELECT * FROM demo_tab ;
The INSERT command is used for adding records (rows) into the specific table.
SYNTAX: INSERT INTO Tab_name (col_1, col_2, col_3) VALUES (1,2,3) ;
The UPDATE command is used to update records or rows in the table.
SYNTAX: UPDATE tab_name SET col_1 = value_1 WHERE col_1 = value_2 ;
NOTE: : It is important to specify the condition in WHERE clause otherwise all the records will be updated. You can also update multiple records.
The DELETE command is used to remove specific record(s) or all records.
SYNTAX: DELETE FROM tab_name WHERE condition ;
NOTE: If you don’t specify the condition(s) in the WHERE clause it will delete all the records.
SYNTAX: DELETE FROM tab_name ;
Thanks For Reading!
Sources: Microsoft Documentation
Read More : Learn SQL Fast