SQL Basics Quiz
47 Questions
1 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What does the % operator do in SQL?

  • It divides two numbers and returns the quotient.
  • It returns the integer remainder of a division operation. (correct)
  • It compares two values for equality.
  • It combines data from two tables.

In the analysis phase of database design, what are attributes?

  • Details about the entities. (correct)
  • Tables that hold data in the system.
  • Relationships between entities.
  • Constraints that ensure data integrity.

What SQL command is used to delete rows from a table?

  • DROP
  • CLEAR
  • REMOVE
  • DELETE (correct)

What is the primary function of the ALTER TABLE command in SQL?

<p>To modify the structure of an existing table. (B)</p> Signup and view all the answers

Which SQL command is used to create a new table?

<p>CREATE TABLE (B)</p> Signup and view all the answers

Which of the following correctly describes the relationships in the analysis phase of database design?

<p>They show how entities are connected. (B)</p> Signup and view all the answers

In SQL, what does the TRUNCATE command accomplish?

<p>It removes all rows from a table without logging each deletion. (C)</p> Signup and view all the answers

What is the effect of using the SET NULL option in SQL?

<p>It sets invalid foreign keys to NULL. (A)</p> Signup and view all the answers

What does the SQL function ABS(n) do?

<p>Returns the absolute value of n (D)</p> Signup and view all the answers

Which SQL function would you use to convert a string to lowercase?

<p>LOWER(s) (A)</p> Signup and view all the answers

What is the purpose of the TRIM(s) function in SQL?

<p>To remove leading and trailing spaces from a string (C)</p> Signup and view all the answers

Which function would return the minute part from a time string?

<p>MINUTE(t) (C)</p> Signup and view all the answers

How is a tuple defined in SQL?

<p>An ordered collection of elements enclosed in parentheses (C)</p> Signup and view all the answers

What does a table in SQL consist of?

<p>A name, fixed columns, and changeable rows (D)</p> Signup and view all the answers

Which SQL function would you use to extract seconds from a time format?

<p>SECOND(t) (B)</p> Signup and view all the answers

In the context of SQL, what does an alias represent?

<p>A temporary name assigned to a column or table (B)</p> Signup and view all the answers

What is the function of COUNT() in SQL?

<p>Counts the number of rows in the dataset (B)</p> 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?

<p>RIGHT JOIN (C)</p> Signup and view all the answers

What is the primary purpose of the UNION operation in SQL?

<p>To generate a single result set from two datasets (C)</p> Signup and view all the answers

What does an INNER JOIN specifically select?

<p>Only rows with matching values in both tables (A)</p> Signup and view all the answers

In the context of database design, what does an Entity Relationship Model (ER diagram) primarily focus on?

<p>Displaying a high-level overview of data entities and relationships (D)</p> Signup and view all the answers

What is the primary responsibility of a database administrator?

<p>Securing the database system from unauthorized access (C)</p> Signup and view all the answers

Which SQL data type is used to store integer values?

<p>TINYINT (B)</p> Signup and view all the answers

What does the Transaction Manager ensure?

<p>Proper execution of transactions (D)</p> Signup and view all the answers

Which data type would you use to store a value like 123.45?

<p>DECIMAL (B)</p> Signup and view all the answers

Which of the following correctly describes 'Query optimization'?

<p>Finds the most efficient way to execute a query (B)</p> Signup and view all the answers

What type of values does the VARCHAR data type store?

<p>Textual values (D)</p> Signup and view all the answers

How many bytes does the INT data type use for storage?

<p>4 bytes (D)</p> Signup and view all the answers

Which role is responsible for turning instructions from the Query Processor into file commands?

<p>Storage Manager (A)</p> Signup and view all the answers

What is the maximum value for an unsigned TINYINT?

<p>255 (D)</p> Signup and view all the answers

Which of the following operations can be performed using the addition operator (+)?

<p>Adding two numeric values (B)</p> 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?

<p>Artificial Key (A)</p> Signup and view all the answers

What does a Foreign Key reference in a database?

<p>A primary key to enforce referential integrity (C)</p> Signup and view all the answers

Which SQL sublanguage is used specifically for controlling user permissions and access?

<p>Data Control Language (DCL) (A)</p> Signup and view all the answers

In the context of aggregate functions, when is the HAVING clause used?

<p>To filter results after grouping (A)</p> Signup and view all the answers

What does an Auto-increment column do in a database?

<p>It automatically increases by one for each new row (D)</p> 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?

<p>Primary Key (C)</p> Signup and view all the answers

Which of the following correctly describes a Composite Primary Key?

<p>Multiple columns used together to identify a row (A)</p> Signup and view all the answers

In the SQL hierarchy, which language is responsible for defining and setting up the structure of the database?

<p>Data Definition Language (DDL) (D)</p> Signup and view all the answers

What is an example of a foreign key in a database schema?

<p>The department an employee manages (C)</p> Signup and view all the answers

Which step involves transforming the ER model into specific database structures?

<p>Logical Design (B)</p> Signup and view all the answers

What type of table uses a hash function to organize rows into buckets?

<p>Hash table (C)</p> Signup and view all the answers

Which of the following correctly defines a subtype entity?

<p>A subset of a supertype entity (C)</p> Signup and view all the answers

What is the primary function of a Materialized View?

<p>To store data persistently, updating as base tables change (C)</p> Signup and view all the answers

Which table structure is characterized by having no specific order for its rows?

<p>Heap table (B)</p> Signup and view all the answers

In database terminology, what does the term 'cardinality' refer to?

<p>Maxima and minima of relationships and attributes (B)</p> Signup and view all the answers

What is the purpose of an Application Programming Interface (API) in the context of databases?

<p>To facilitate communication between SQL and programming languages (D)</p> Signup and view all the answers

Flashcards

Database Administrator

Manages the database's security, controls user access, and ensures data integrity.

Authorization

The process of granting permissions to users to access specific data or perform actions within a database.

Rules in a database

Constraints that enforce data integrity and consistency, ensuring data meets specific criteria and business requirements.

Query Processor

Interprets and executes user queries, finding the most efficient way to retrieve or modify data.

Signup and view all the flashcards

Query Optimization

The process of finding the most efficient way to execute a query, minimizing the time it takes to retrieve or modify data.

Signup and view all the flashcards

Storage Manager

Manages the physical storage of data, translating query requests into low-level file commands.

Signup and view all the flashcards

Transaction Manager

Ensures that database transactions are executed correctly, preventing conflicts and recovering from failures.

Signup and view all the flashcards

INT Data Type

Stores whole numbers, both positive and negative, with different storage sizes depending on the specific INT variant.

Signup and view all the flashcards

DECIMAL Data Type

Stores numbers with fractional parts, used for representing values with decimal places.

Signup and view all the flashcards

VARCHAR Data Type

Stores variable-length text strings, allowing for flexibility in storing textual data.

Signup and view all the flashcards

SQL Functions

Pre-built commands in SQL that perform specific operations on data, like converting text to lowercase or extracting time components.

Signup and view all the flashcards

ABS(n)

Returns the absolute value of a number 'n'. The absolute value is always a positive number.

Signup and view all the flashcards

LOWER(s)

Converts a string 's' to lowercase.

Signup and view all the flashcards

TRIM(s)

Removes leading and trailing spaces from a string 's'.

Signup and view all the flashcards

HOUR(t), MINUTE(t), SECOND(t)

Functions that extract the hour, minute, or second from a time value 't'.

Signup and view all the flashcards

Tuple

An ordered collection of elements, usually enclosed in parentheses. It represents a row of data in a table.

Signup and view all the flashcards

Table

A structured collection of data organized in rows and columns with a specific name. It's the foundation of relational databases.

Signup and view all the flashcards

Column

A vertical section in a table that holds data of a specific type (text, numbers, etc.) and has a unique name.

Signup and view all the flashcards

Cell

A single column of a single row within a table.

Signup and view all the flashcards

Literal

An explicit value directly in a SQL statement, such as a string, number, or binary value.

Signup and view all the flashcards

Keyword

A reserved word in SQL with a specific meaning, like SELECT, FROM, or WHERE. Used to instruct the database what to do.

Signup and view all the flashcards

Identifier

A name given to database objects like tables, columns, or views. Identifies a specific element in the database.

Signup and view all the flashcards

Primary Key

A column or group of columns that uniquely identifies each row in a table. Ensures data integrity.

Signup and view all the flashcards

Foreign Key

A column or group of columns that references a primary key in another table, establishing relationships.

Signup and view all the flashcards

Data Definition Language (DDL)

A set of SQL commands that define and modify the database structure, such as creating or altering tables.

Signup and view all the flashcards

COUNT()

A SQL function that counts the number of rows in a dataset.

Signup and view all the flashcards

JOIN

A SQL statement that combines data from two tables, known as the left and right tables, into a single result. The columns must have comparable data types.

Signup and view all the flashcards

INNER JOIN

A type of JOIN that selects only rows that have matching values in both the left and right tables.

Signup and view all the flashcards

ER Diagram

A high-level diagram that shows how data entities relate to each other. It focuses on data requirements and relationships, without worrying about how the data will be stored or implemented in a database.

Signup and view all the flashcards

Equijoin

A type of JOIN that compares columns of two tables using the equals (=) operator.

Signup and view all the flashcards

Entity Type

A set of things with common characteristics. For example, all employees in a company.

Signup and view all the flashcards

Relationship Type

A connection between two or more entity types. For example, the relationship between employees and departments.

Signup and view all the flashcards

Attribute Type

A characteristic of an entity type. For example, an employee's salary.

Signup and view all the flashcards

Entity Instance

A specific occurrence of an entity type. For example, a particular employee named Sam Snead.

Signup and view all the flashcards

Relationship Instance

A specific occurrence of a relationship type. For example, the statement 'Maria Rodriguez manages Sales'.

Signup and view all the flashcards

Attribute Instance

A specific value of an attribute type. For example, the salary of $35,000.

Signup and view all the flashcards

Cardinality

The maximum and minimum number of entities that can be involved in a relationship or attribute.

Signup and view all the flashcards

Subtype Entity

A subset of a supertype entity. For example, managers are a subset of employees.

Signup and view all the flashcards

Unary Minus (-)

Reverses the sign of a single numeric value.

Signup and view all the flashcards

Binary Minus (-)

Subtracts one numeric value from another.

Signup and view all the flashcards

Modulo (%)

Divides one numeric value by another and returns the integer remainder.

Signup and view all the flashcards

Database Analysis Phase

Defines the database's requirements without specifying a particular system.

Signup and view all the flashcards

Database Logical Design

Transforms database requirements into a structured system format.

Signup and view all the flashcards

Create Table

Creates a new table in the database.

Signup and view all the flashcards

Insert

Adds rows of data into an existing table.

Signup and view all the flashcards

Select

Retrieves data from a table based on specific criteria.

Signup and view all the flashcards

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.

Quiz Team

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.

More Like This

SQL Commands Quiz
3 questions

SQL Commands Quiz

EminentCelebration avatar
EminentCelebration
Use Quizgecko on...
Browser
Browser