SQL Commands and Functions Lab Guide
SQL Commands and Functions Lab Guide
GROUP BY aggregates data based on one or more columns, allowing for operations like counting occurrences; ORDER BY sorts the resultant data set by specified columns, enhancing readability and analysis; INDEX increases query performance by allowing faster retrieval of records, though it may slow down data insertion and deletion .
SQL triggers execute predetermined actions automatically when specific database events, such as inserts, updates, or deletes, occur. For example, a 'before insert' trigger in a Students table might modify inserted data to ensure name capitalization to maintain data uniformity .
Arithmetic operators perform mathematical calculations, while logical operators filter data based on conditions; comparison operators are used to match exact values; special operators like DISTINCT ensure unique results; and set operators like UNION combine results from multiple queries .
INNER JOIN combines records from two tables where there are matching values in both; LEFT JOIN returns all records from the left table and matched records from the right; NATURAL JOIN automatically joins tables based on columns with the same name, returning all combinations .
Transactions are units of work executed as a single operation, ensuring consistency and integrity of the database. Savepoints allow setting intermediate points within a transaction to which one can rollback; ROLLBACK undoes transaction changes to a savepoint or entirely; COMMIT applies all changes permanently .
Constraints enforce rules for data stored in tables, ensuring its accuracy and reliability. Examples include PRIMARY KEY for unique identification, NOT NULL to prevent missing values, and CHECK constraints to enforce specific conditions, such as ensuring age is greater than or equal to 18 .
PL/SQL enables procedural logic within SQL queries by allowing blocks of code that can take advantage of variables, control structures like loops, and condition-testing inside SQL, enhancing the functionality and control over SQL query execution .
The expected outputs when performing basic DDL operations are as follows: when creating a table, the output should be 'Table created'; when altering the table, the output should be 'Table altered'; and when dropping the table, the output should be 'Table dropped' .
Mechanisms involved in user and role management include creating and defining users, assigning them specific privileges for accessing database objects, and revoking those privileges to control access. This ensures that only authorized individuals can perform operations, thus enhancing security .
Number functions return numeric values such as the length of a string; aggregate functions calculate values from multiple rows, e.g., AVG(Age) from the Students table; character functions transform text, such as converting all characters to uppercase; conversion functions change data types, e.g., casting a string to a date; and date functions provide current date values .