HAVING,INDEX,COMMIT & ROLLBACK SQL CLAUSES
WHAT IS INDEX? Indexes help us retrieve data from tables quicker. Tables can have millions of rows but usually only a subset of those rows is needed to work on. This is where the concept of an index comes from. With an index, it reads the index table, find where that row is held and then fetches it- much faster!
CREATE INDEX Syntax Creates an index on a table. Duplicate values are allowed: CREATE INDEX index_name ON table_name; //BASIC SYNTAX SYNTAX TWO CREATE INDEX index_name ON table_name (column1, column2, ...);
HAVING CLAUSE HAVING filters records that work on summarized GROUP BY results. HAVING applies to summarized group records, whereas WHERE applies to individual records. Only the groups that meet the HAVING criteria will be returned. HAVING requires that a GROUP BY clause is present. WHERE and HAVING can be in the same query.
Syntax FOR HAVING SELECT column-names FROM table-name WHERE condition GROUP BY column-names HAVING condition
COMMIT AND ROLLBACK The following commands are used to control transactions. COMMIT − to save the changes. ROLLBACK − to roll back the changes.(UNDO)
The COMMIT Command The COMMIT command is the transactional command used to save changes invoked by a transaction to the database. The COMMIT command saves all the transactions to the database since the last COMMIT or ROLLBACK command.
The syntax for the COMMIT command SQL> DELETE FROM TABLE_NAME WHERE COLUMN_NAME = VALUE; SQL> COMMIT; THIS A SYNTAX which would delete those records from the table which have SPECIFIED COLUMN_NAME = VALUE and then COMMIT the changes in the database.
The ROLLBACK Command The ROLLBACK command is the transactional command used to undo transactions that have not already been saved to the database. This command can only be used to undo transactions since the last COMMIT or ROLLBACK command was issued.
The syntax for a ROLLBACK command SQL> DELETE FROM TABLE_NAME WHERE COLUMN_NAME = VALUE; SQL> ROLLBACK; THIS A SYNTAX which would delete those records from the table which have the COLUMN_NAME = VALUE and then ROLLBACK the changes in the database.
END OF SLIDE