Database Systems Lecture2
Database Systems Lecture2
SQL Syntax
▪ SQL is followed by unique set of rules and guidelines called
Syntax.
▪ All the SQL statements start with any of the keywords like SELECT,
INSERT, UPDATE, DELETE, ALTER, DROP, CREATE, USE, SHOW
and all the statements end with a semicolon (;).
▪ Example
SELECT *
FROM departments;
SQL SELECT Statement
▪ Selecting Specific Columns
DESC[RIBE] tablename
Writing SQL Statements
…
Null Values in Arithmetic Expressions
…
Column aliases
Defining a Column Alias
➢ Renames a column heading
➢ Is useful with calculations
➢ Immediately follows the column name (There can also be the optional
AS keyword between the column name and alias.)
➢ Requires double quotation marks if it contains spaces or special
characters, or if it is case-sensitive
Using Column Aliases
…
Using Literal Character Strings
…
Alternative Quote (q) Operator
– Specify your own quotation mark delimiter.
– Select any delimiter.
– Increase readability and usability.
SELECT department_name || ' Department' ||
q'['s Manager Id: ]'
|| manager_id
AS "Department and Manager"
FROM departments;
Duplicate Rows
…
SELECT DISTINCT department_id
FROM employees;
…
References
➢ SQL TUTORIAL , Simply Easy Learning by tutorialspoint.com
➢ Oracle Slides