Podcast
Questions and Answers
What does the % operator do in SQL?
What does the % operator do in SQL?
In the analysis phase of database design, what are attributes?
In the analysis phase of database design, what are attributes?
What SQL command is used to delete rows from a table?
What SQL command is used to delete rows from a table?
What is the primary function of the ALTER TABLE command in SQL?
What is the primary function of the ALTER TABLE command in SQL?
Signup and view all the answers
Which SQL command is used to create a new table?
Which SQL command is used to create a new table?
Signup and view all the answers
Which of the following correctly describes the relationships in the analysis phase of database design?
Which of the following correctly describes the relationships in the analysis phase of database design?
Signup and view all the answers
In SQL, what does the TRUNCATE command accomplish?
In SQL, what does the TRUNCATE command accomplish?
Signup and view all the answers
What is the effect of using the SET NULL option in SQL?
What is the effect of using the SET NULL option in SQL?
Signup and view all the answers
What does the SQL function ABS(n) do?
What does the SQL function ABS(n) do?
Signup and view all the answers
Which SQL function would you use to convert a string to lowercase?
Which SQL function would you use to convert a string to lowercase?
Signup and view all the answers
What is the purpose of the TRIM(s) function in SQL?
What is the purpose of the TRIM(s) function in SQL?
Signup and view all the answers
Which function would return the minute part from a time string?
Which function would return the minute part from a time string?
Signup and view all the answers
How is a tuple defined in SQL?
How is a tuple defined in SQL?
Signup and view all the answers
What does a table in SQL consist of?
What does a table in SQL consist of?
Signup and view all the answers
Which SQL function would you use to extract seconds from a time format?
Which SQL function would you use to extract seconds from a time format?
Signup and view all the answers
In the context of SQL, what does an alias represent?
In the context of SQL, what does an alias represent?
Signup and view all the answers
What is the function of COUNT() in SQL?
What is the function of COUNT() in SQL?
Signup and view all the answers
Which type of JOIN in SQL will include all rows from the right table and only matched rows from the left table?
Which type of JOIN in SQL will include all rows from the right table and only matched rows from the left table?
Signup and view all the answers
What is the primary purpose of the UNION operation in SQL?
What is the primary purpose of the UNION operation in SQL?
Signup and view all the answers
What does an INNER JOIN specifically select?
What does an INNER JOIN specifically select?
Signup and view all the answers
In the context of database design, what does an Entity Relationship Model (ER diagram) primarily focus on?
In the context of database design, what does an Entity Relationship Model (ER diagram) primarily focus on?
Signup and view all the answers
What is the primary responsibility of a database administrator?
What is the primary responsibility of a database administrator?
Signup and view all the answers
Which SQL data type is used to store integer values?
Which SQL data type is used to store integer values?
Signup and view all the answers
What does the Transaction Manager ensure?
What does the Transaction Manager ensure?
Signup and view all the answers
Which data type would you use to store a value like 123.45?
Which data type would you use to store a value like 123.45?
Signup and view all the answers
Which of the following correctly describes 'Query optimization'?
Which of the following correctly describes 'Query optimization'?
Signup and view all the answers
What type of values does the VARCHAR data type store?
What type of values does the VARCHAR data type store?
Signup and view all the answers
How many bytes does the INT data type use for storage?
How many bytes does the INT data type use for storage?
Signup and view all the answers
Which role is responsible for turning instructions from the Query Processor into file commands?
Which role is responsible for turning instructions from the Query Processor into file commands?
Signup and view all the answers
What is the maximum value for an unsigned TINYINT?
What is the maximum value for an unsigned TINYINT?
Signup and view all the answers
Which of the following operations can be performed using the addition operator (+)?
Which of the following operations can be performed using the addition operator (+)?
Signup and view all the answers
Which type of key is a single-column primary key used when there is no suitable primary key existing?
Which type of key is a single-column primary key used when there is no suitable primary key existing?
Signup and view all the answers
What does a Foreign Key reference in a database?
What does a Foreign Key reference in a database?
Signup and view all the answers
Which SQL sublanguage is used specifically for controlling user permissions and access?
Which SQL sublanguage is used specifically for controlling user permissions and access?
Signup and view all the answers
In the context of aggregate functions, when is the HAVING clause used?
In the context of aggregate functions, when is the HAVING clause used?
Signup and view all the answers
What does an Auto-increment column do in a database?
What does an Auto-increment column do in a database?
Signup and view all the answers
What is described as a column or group of columns used to uniquely identify a row in a table?
What is described as a column or group of columns used to uniquely identify a row in a table?
Signup and view all the answers
Which of the following correctly describes a Composite Primary Key?
Which of the following correctly describes a Composite Primary Key?
Signup and view all the answers
In the SQL hierarchy, which language is responsible for defining and setting up the structure of the database?
In the SQL hierarchy, which language is responsible for defining and setting up the structure of the database?
Signup and view all the answers
What is an example of a foreign key in a database schema?
What is an example of a foreign key in a database schema?
Signup and view all the answers
Which step involves transforming the ER model into specific database structures?
Which step involves transforming the ER model into specific database structures?
Signup and view all the answers
What type of table uses a hash function to organize rows into buckets?
What type of table uses a hash function to organize rows into buckets?
Signup and view all the answers
Which of the following correctly defines a subtype entity?
Which of the following correctly defines a subtype entity?
Signup and view all the answers
What is the primary function of a Materialized View?
What is the primary function of a Materialized View?
Signup and view all the answers
Which table structure is characterized by having no specific order for its rows?
Which table structure is characterized by having no specific order for its rows?
Signup and view all the answers
In database terminology, what does the term 'cardinality' refer to?
In database terminology, what does the term 'cardinality' refer to?
Signup and view all the answers
What is the purpose of an Application Programming Interface (API) in the context of databases?
What is the purpose of an Application Programming Interface (API) in the context of databases?
Signup and view all the answers
Study Notes
Database Roles
- Database administrators secure the database system from unauthorized users, controlling user access.
- Authorization limits what each user can access.
- Rules ensure the database system maintains structural and business consistency.
- Query processors read and understand queries, creating plans to retrieve or modify data, and returning results to applications.
- Query optimization finds the most efficient way to execute queries.
- Storage managers translate query processor instructions into file commands to retrieve or modify data, using indexes for faster location.
- Transaction managers ensure transactions execute correctly, prevent conflicts between concurrent transactions, and restore the database in case of failure.
SQL Data Types
- INT: Stores integers (positive and negative).
Category | Example | Data Type | Storage | Notes |
---|---|---|---|---|
Integer | 34 and -739448 | TINYINT | 1 byte | Signed: -128 to 127 Unsigned: 0 to 255 |
SMALLINT | 2 bytes | Signed: -32,768 to 32,767 Unsigned: 0 to 65,535 |
||
MEDIUMINT | 3 bytes | Signed: -8,388,608 to 8,388,607 Unsigned: 0 to 16,777,215 |
||
INT | 4 bytes | Signed: -2,147,483,648 to 2,147,483,647 Unsigned: 0 to 4,294,967,295 |
||
BIGINT | 8 bytes | Signed: -263 to 263 -1 Unsigned: 0 to 264 -1 |
Arithmetic and Comparison Operators
- +: Adds two numeric values (e.g., 4 + 3 = 7).
- -: Reverses the sign of a numeric value (e.g., -(-2) = 2).
- -: Subtracts one numeric value from another (e.g., 11 - 5 = 6).
- %: Returns the integer remainder of a division (e.g., 5 % 2 = 1).
- =: Compares for equality (e.g., 1 = 2 is FALSE).
-
: Compares using greater than (e.g., '2019-08-13' > '2021-08-13' is FALSE).
- !=: Compares for inequality (e.g., 1 != 2).
Database Design Phases
- Analysis: Outlines database needs, focusing on entities (things or people), relationships between entities, and attributes (details about entities).
- Logical Design: Converts database requirements into a specific system format (tables, columns, keys).
- Physical Design: Optimizes data retrieval speed by adding indexes to data tables.
SQL Commands
- CREATE TABLE: Creates a table (e.g.,
CREATE TABLE employees (...)
). - INSERT INTO: Inserts new rows into a table (e.g.,
INSERT INTO employees
). - SELECT: Retrieves data from a table (e.g.,
SELECT first_name, last_name FROM employees
). - UPDATE: Modifies data within a table (e.g.,
UPDATE employees SET salary = 55000 WHERE employee_id = 101
). - DELETE FROM: Removes rows from a table (e.g.,
DELETE FROM employees WHERE employee_id = 101
). - ALTER TABLE: Modifies existing tables (adding or deleting columns) (e.g.,
ALTER TABLE employees ADD phone_number VARCHAR(15)
).
SQL Operators
- BETWEEN: Checks if a value falls within a specified range.
- LIKE: Matches text against a pattern in a column. Uses '%' for multiple characters and '_' for single characters.
- Alias: Temporary names assigned to table columns (e.g.,
SELECT first_name AS "First Name"
).
SQL Functions
- ABS(n): Returns the absolute value of a number.
- LOWER(s): Converts a string to lowercase.
- TRIM(s): Removes leading and trailing spaces from a string.
- HOUR(t), MINUTE(t), SECOND(t): Extracts the hour, minute, and second from a time value.
Data Structure
- Tuple: Ordered collection of elements.
- Table: Stores data with columns and rows.
- Column: Holds data of a specific type (e.g., number, text).
- Row: Holds values for each column.
- Cell: A single column within a row.
SQL Elements
- Literals: Explicit string, numeric, or binary values.
- Keywords: Words with special meaning (e.g., SELECT, FROM, WHERE).
- Identifiers: Objects in the database (e.g., tables, columns).
- Primary Key: Column uniquely identifying a row.
- Simple Primary Key: Single column.
- Composite Primary Key: Multi-column.
- Artificial Key: Single-column primary key created when no other suitable key exists.
- Candidate Key: Simple or composite column that uniquely identifies a row (and is minimal).
- Auto-Increment Column: Numeric column that automatically increases with each new row.
- Foreign Key: References a primary key (crucial for relational connections).
SQL Sublanguages
- DDL(Data Definition Language): Defines database structure (e.g., creating tables).
- DQL (Data Query Language): Retrieves data from the database (e.g., SELECT).
- DML (Data Manipulation Language): Manipulates table data (e.g., INSERT, UPDATE, DELETE).
- DCL (Data Control Language): Controls user permissions (e.g., GRANT, REVOKE).
- DTL (Data Transaction Language): Manages database transactions (e.g., COMMIT, ROLLBACK).
Aggregate Functions
- COUNT(): Counts rows.
- MIN(): Finds the minimum value.
- MAX(): Finds the maximum value.
- SUM(): Computes the sum of values.
- AVG(): Computes the average of values.
JOIN and Union in SQL
- Join combines data from multiple tables (e.g., INNER JOIN, FULL JOIN, LEFT JOIN, RIGHT JOIN, OUTER JOIN, UNION).
- Equijoins use =, non-equijoins (e.g., <, >).
- Cross-join combines data from two tables without matching based on columns.
Entity Relationship Model (ERM)
- ER diagram defines entity relations/links.
- Entities represent real-world objects (e.g., employees, products).
- Relationships show how entities interact (e.g., employee to department).
- Attributes of Entities provide details about entities.
- Instances are specific instances of entities.
- Relationships are defined by Instances between entities.
Table Structures
- Heap table: No specific order for rows (useful for bulk loading).
- Sorted table: Ordered by a column for fast lookups.
- Hash table: uses a hash to place rows into buckets for quick lookup.
- Table cluster: Reduces data access times by grouping related tables together.
Other Definitions
- API (Application Programming Interface): Allows different programs to communicate and interact.
- SQL Client: Text-based interface for interacting with the database.
- Business Rules: Policies used within a database (specific to the system).
- Subquery (Nested Query/Inner Query): SQL query nested within another query.
- Materialized View: a stored representation of a query's result set.
- Cardinality: Shows maximum and minimum values of entity relations.
- Subtype Entity: set of related entities within a larger supertype.
- Normalization: Reduces data redundancy by creating different tables.
- Denormalization: Increases redundancy in a database for improved efficiency.
- Hit Ratio: Percentage of results retrieved from a database.
- Binary Search: A way to locate matching data in a sorted database.
- Dense and Sparse Index: Different indexing methods with varying storage characteristics.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
Test your knowledge of essential SQL commands and concepts, including data manipulation, table management, and attributes in database design. This quiz covers various SQL functions and operators that are critical for effective database management.