


















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A comprehensive guide to understanding and implementing foreign keys in mysql. It covers key concepts such as referential integrity, data integrity, and the use of foreign keys to maintain data consistency. Practical examples and explanations of various foreign key actions, such as on delete cascade and on update set null. It also demonstrates how to define foreign keys using both create table and alter table statements. Additionally, the document explores the use of foreign key checks and the alter table statement for modifying table structures.
Typology: Study notes
1 / 58
This page cannot be seen from the preview
Don't miss anything!
✓ Aggregate Functions ✓ Set Operations
Example: ID NAME 1 Jack 2 Harry 3 Jackson
3 Jackson 4 Stephan 5 David
Union SQL query will be: SELECT * FROM First UNION SELECT * FROM Second;
1 Jack 2 Harry 3 Jackson 4 Stephan 5 David
2. Union All Union All operation is equal to the Union operation. It returns the set without removing duplication and sorting the data. Syntax: SELECT column_name FROM table UNION ALL SELECT column_name FROM table2;
SELECT * FROM First UNION ALL SELECT * FROM Second;
1 Jack 2 Harry 3 Jackson 3 Jackson 4 Stephan 5 David
Operator Returns UNION All distinct rows selected by either query UNION ALL All rows selected by either query, including all duplicates INTERSECT All distinct rows selected by both queries MINUS All distinct rows selected by the first query but not the second
Difference between the COMMIT and ROLLBACK Comparison Based on Parameters
Definition/ Basic A COMMIT statement is used to save the changes on the current transaction is permanent. A Rollback statement is used to undo all the changes made on the current transaction. Transaction condition Once the current transaction is completely executed using the COMMIT command, it can't undo its previous state. Whereas in the Rollback statement, once the current transaction is successfully executed, it can reach its previous state using the ROLLBACK command. Syntax of Statement Commit; Rollback; Occurrence The COMMIT statement is applied when the transaction is completed. The Rollback statement occurs when the transaction is either aborted, power failure, or incorrect execution of system failure. Successfully executed the statement. If all the statements are executed successfully without any error, the COMMIT statement will permanently save the state. If any operations fail during the completion of a transaction, it shows all the changes have not been successfully executed, and we can undo them using the ROLLBACK statement. Visible change When we perform the commit command, the current transaction statement becomes permanent and visible to all users. Whereas the rollback command is also visible to all users, even the current transaction may contain the wrong or right information.
Note: A NULL value is different from a zero value or a field that contains spaces. A field with a NULL value is one that has been left blank during record creation!
The IS NULL Operator
SELECT CustomerName, ContactName, Address FROM Customers WHERE Address IS NOT NULL;
Example for COUNT() with DISTINCT SELECT COUNT(DISTINCT COMPANY) FROM PRODUCT_MAST; Example for COUNT() with GROUP BY SELECT COMPANY, COUNT() FROM PRODUCT_MAST GROUP BY COMPANY; Example for COUNT() with HAVING SELECT COMPANY, COUNT() FROM PRODUCT_MAST GROUP BY COMPANY HAVING COUNT(*)>2;
Example for COUNT with WHERE
2. SUM() with WHERE SELECT SUM(COST) FROM PRODUCT_MAST WHERE QTY>3; 3. SUM() with GROUP BY SELECT SUM(COST) FROM PRODUCT_MAST WHERE QTY>3 GROUP BY COMPANY; 4. SUM() with HAVING SELECT COMPANY, SUM(COST) FROM PRODUCT_MAST GROUP BY COMPANY HAVING SUM(COST)>=170; 2. SUM Function
Syntax : Example:
4.MAX Function MAX function is used to find the maximum value of a certain column. This function determines the largest value of all selected values of a column. Syntax
or MAX( [ALL|DISTINCT] expression ) Example: (^) SELECT MAX(RATE) FROM PRODUCT_MAST;
or MIN( [ALL|DISTINCT] expression ) Example: SELECT MIN(RATE) FROM PRODUCT_MAST;
Types of Integrity Constraint