Categories of SQL Statements 1.Data manipulation language (DML) 1.Data manipulation language (DML) statements begin with INSERT, UPDATE, DELETE, or MERGE and are used to modify the table by entering new rows, changing existing rows, or removing existing rows. 2.Data definition language (DDL) statements set up, change, and remove data structures from the database. The keywords CREATE, ALTER, DROP, RENAME, and TRUNCATE begin DDL statements. 3.Transaction control (TCL) statements are used to manage the changes made by DML statements. Changes to the data are executed using COMMIT, ROLLBACK, and SAVEPOINT. TCL changes can be grouped together into logical transactions. 4.Data control language (DCL) keywords GRANT and REVOKE are used to give or remove access rights to the database and the structures within it.
a SELECT statement must include the following: SELECTA SELECT clause, which specifies the columns to be displayed FROM A FROM clause, which specifies the table containing the columns listed in the SELECT clause Select ………...[column name] From …….……..[table name]
A SELECT statement can do the following: ProjectionProjection: Used to choose columns in a table SelectionSelection: Used to choose rows in a table JoinJoin: Used to bring together data that is stored in different tables by creating a link between them (you will learn about this later!)
Aliases "friendly" name Column aliases let you rename columns in the output Why column Alias - Renames a column heading - Is useful with calculations - Immediately follows the column name - May have the optional AS keyword between the column name and alias - Requires double quotation marks if the alias contains spaces or special characters or is case-sensitive
Concatenation (||) Concatenation means to connect or link together in a series Select columnname || columnname From tablename Select first_name || last_name From empolyees You cane use column alias to rename the connected columns.
DESCRIBE display the structure of a table. Why describe? DESCRIBE returns the table name, table schema, tablespace name, indexes, triggers, constraints, and comments as well as the data types, primary and foreign keys, and which columns can be nullable. DESC[RIBE] tablename; as DESCRIBE departments;
DISTINCT Used to eliminate duplicate rows. DISTINCT DISTINCT automatically displays the output in alphabetical order.
Limiting rows selected Used to limit the number of rows retrieved from the quarry note note : An alias cannot be used in the WHERE clause! A WHERE clause contains a condition that must be met, and it directly follows the FROM clause in a SQL statement. Where clause
The default sort order is ascending. - Numeric values are displayed lowest to highest. - Date values are displayed with the earliest value first. - Character values are displayed in alphabetical order. - Null values are displayed last in ascending order and first in descending order.
aliasIt is also possible to order data by using a column alias. The alias used in the SELECT statement is added to the ORDER BY clause. SELECT title, year AS "Recording Date" FROM d_cds ORDER BY "Recording Date"
What does this order by mean? Select first_name, last_name, salary, job_id From employees Where job_id = 10 Order by 3
GOOD LUCK SEE YOU NEXT MEETING Raafat Rashad email@example.com firstname.lastname@example.org