|
What is SQL?SQL is a non-procedural programming language designed to implement relational algebra. It is standardized by the ANSI and is a required feature of all relational database management systems. SQL serves all three database language functions (DDL=data defintion language, DCL=data control language, and DML=data manipulation language). What is the general DML syntax of SQL?The base syntax isSELECT xxxxxxxxxFROM xxxxxxxxxWHERE xxxxxxxx;the verb SELECT is used to make projections and computations, the word FROM is used to identify source tables, and the verb WHERE is used to specifiy selection or join conditions. Additional phrases and functions are available. What is the semicolon for?In SQL carriage returns and line feeds are used to make the program pretty and readable. So we need some typable printable character to signal the end of the program. The ANSI has chosen the semicolon for that function. It is good form to always place the semicolon at the end in its own line because this practive improves editability. What if there is more than one selection condition?You may use as many conditions as you need by placing each in an AND or OR or AND NOT or OR NOT clause. These are equivalent to WHERE and work in conjunction with WHERE. What are some of the other clauses?The additional clauses used most often are ORDER BY for setting sort parameters of the result table and GROUP BY for setting the level of summation or other group arithmetic sub groups. Why do they use dots in column names?To avoid ambiguity when referring to column names in selection and projection clauses the practice is to use the full naming syntax which is TABLENAME.COLUMNNAME. For example ORDERS.AMOUNT refers to the column AMOUNT in the table ORDERS. Where do the letters a,b,c, come from in SQL statements?These are short aliases arbitrarily assigned to table names to make the SQL more typable and more readable. The alias is assigned in the FROM clause and may be used in any other clause even if it comes before the FROM clause. What are Jamal's four stupid rules for writing SQL?To produce very readable and editable SQL and to avoid stupid errors (1) always use aliases (2) always use the full column naming syntax as aliasname.columnname even when the table name may be inferred, (3) always use a different line for each clause, and (4) always place the semicolon in its own little line. What are the DDL and DCL SQL clauses?DDL is used to define the data dictionary items which itself is a relational database. Table defintions are made using the CREATE TABLE and DROP TABLE commands. Data access is controlled using the GRANT ACCESS command. |