Chapter 3 - SQL (Structured Query Language) Flashcards

1
Q

What are some Characteristics of SQL?

A

It is not a complete programming language, but rather a data sublanguage.
It was developed by IBM in the late 1970s. Endorsed and adopted by ANSI in 1992

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the SQL Statement Categories?

A

Data Definition Language (DDL) - Used to create DB structures
Data Manipulation Language (DML) - Used to query, insert, modify, and delete
SQL/Persistent Stored Modules (SQL/PSM) - Extends SQL by adding procedural programming capabilities
Transaction Control Language (TCL) - Marks transaction boundaries
Data Control Language (DCL) - Grants and revokes DB permissions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you Describe the Structure of a Table in MySQL?

A

Use the DESC statement. Example: “DESC DEPARTMENT”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the * mean when Querying?

A
  • means “all”

When using the query “SELECT * FROM ____” you are selecting all applicable data from the relation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the basic SQL DDL Statements for Creating Database Structures?

A

CREATE - creates DB objects
ALTER - Modify the structure and/or characteristics of DB objects
DROP - To delete DB objects
TRUNCATE - Delete table data while keeping the structure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the SQL CREATE TABLE statement format?

A

CREATE TABLE NEW_TABLE_NAME(
ColumnName DataType OptionalColumnConstraints
ColumnName DataType OptionalColumnConstraints
ColumnName DataType OptionalColumnConstraints

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the Different Data Types available in all DBMS products? (Pg. 146)

A

Numeric Data Types
Date and Time Data Types
String Data Types
Other Data Types

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the SQL DML !Statements! that Query Databases and Modify Data in the Tables?

A

INSERT - Adding data to a relation
UPDATE - Modifying data in a relation
DELETE - Deleting data in a relation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

In the SQL Query Framework, what are the 3 Clauses and what do they do?

A

SQL SELECT - Specifies which columns are to be listed in the query results
SQL FROM - Specifies which tables are to be used in the query
SQL WHERE - Specifies which rows are to be listed in the query results

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the DISTINCT keyword in a SELECT statement’s effect?

A

It brings back all specific values in the query

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are some of the SQL Comparison Operators? (Part 1)

A

<> = is NOT equal to (!= also applicable)
IN = Equal to one of a set of values
NOT IN = Not equal to any of a set of values
BETWEEN = Within a range of numbers
LIKE = Matches a set of characters
IS NULL = Is equal to NULL

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the ORDER BY clause with DESC/ASC Keywords?

A

By default, SQL Server sorts in ascending order, so ordering in descending order would be “ORDER BY TableName DESC”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the ORDER BY clause with DESC/ASC Keywords?

A

By default, SQL Server sorts in ascending order, so ordering in descending order would be “ORDER BY TableName DESC”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the 3 Options for the SQL Where Clauses?

A

Compound clauses (Use logical operators such as AND, OR, NOT)
Ranges (Use range of values like <, <=, >=)
Wildcards (Use underscores for each space needed or percent % signs for multiple spaces)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you Include or Exclude Rows that contain NULL values?

A

Use the IS NULL or IS NOT NULL comparison values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are some of the SQL Built-In Aggregate Functions?

A

COUNT - Count number of rows in the table
SUM - Sum of all values (numeric columns only)
AVG - Average of all values (numeric columns only)
MIN - Minimum value of all values
MAX - Maximum value of all values

16
Q

What is the GROUP BY clause in SQL and why is it useful?

A

The GROUP BY clause groups rows by common values. It’s useful to view the table in ordered groups, such as departments or students in a certain dormitory.

17
Q

How would you Structure a Query for GROUP BY with the HAVING clause?

A

SELECT ColumnName
FROM TABLE
GROUP BY Column
HAVING CLAUSE

It is like having a filter condition on the GROUP BY results

18
Q

What are the 2 Techniques for Querying Data from Multiple Tables?

A

SQL Subquery
SQL Join

19
Q

What is the Limitation to the Subquery Approach?

A

Subqueries only work if the results are coming from a single table. If we need to display data from two or more tables, then subqueries do not work.

20
Q

How do we Use the SQL Join technique?

A

Use the WHERE clause involving the PK of one table and the Foreign Key (FK) of another.
Use the JOIN ON Syntax: still involves the PK of one table and the FK of another. JOIN ON combines two or more tables together.

21
Q

What are the 3 Queries for Multiple Tables?

A

SQL Inner Joins (also known as SQL Equijoins)
SQL Left Outer Joins
SQL Right Outer Joins

22
Q

How do SQL Inner Joins (SQL Equijoins) work?

A

An SQL WHERE clause is added to select only those rows where the primary key matches the foreign key. It requires that the values in the two columns are equal to each other.

23
Q

How do SQL Left Outer Joins and SQL Right Outer Joins work and differ from SQL Equijoins?

A

In SQL Left Outer and Right Outer Joins, the query will show the full data from one of the selected tables, including the rows that do not have a matching value in the PK/FK. Outer joins will produce NULL values in the non-matching rows of the unselected table.

24
Q

What are the 3 SQL DML !Commands! for Modifying and Deleting data from a DB? (Slightly different than the DML Statements)

A

Insert
Modify
Delete

25
Q

What are the SQL DDL Statements?

A

The DROP TABLE
The ALTER TABLE
When altering a table, you can DROP constraints or other rules