Chapter 7 Introduction to Structured Query Language (SQL)

Chapter 7 Introduction to Structured Query Language (SQL)

memorize.aimemorize.ai (lvl 286)
Section 1

Preview this deck

Structured Query Language (SQL) §

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (58)

Section 1

(50 cards)

Structured Query Language (SQL) §

Front

Nonprocedural language with basic command vocabulary set of less than 100 words § Differences in SQL dialects are minor

Back

SELECT command

Front

Acts as a subquery and is executed first

Back

Subquery

Front

Query embedded/nested inside another query

Back

Command §

Front

CREATE SCHEMA AUTHORIZATION {creator}; § Seldom used directly

Back

Tasks to be Completed Before Using a New RDBMS Create database structure

Front

RDBMS creates physical files that will hold database § Differs from one RDBMS to another §

Back

Optional WHERE clause §

Front

Adds conditional restrictions to the SELECT statement

Back

Copying Parts of Tables §

Front

SQL permits copying contents of selected table columns § Data need not be reentered manually into newly created table(s) § Table structure is created § Rows are added to new table using rows from another table

Back

Syntax §

Front

INSERT INTO tablename SELECT columnlist FROM tablename §

Back

Comparison Operators §

Front

Add conditional restrictions on selected table contents § Used on: § Character attributes § Dates

Back

ALTER TABLE command §

Front

Followed by a keyword that produces the specific change one wants to make § Options include ADD, MODIFY, and DROP §

Back

Selecting Rows Using Conditional Restrictions

Front

Used to select partial table contents by placing restrictions on the rows §

Back

Following syntax enables to specify which rows to select

Front

SELECT columnlist § FROM tablelist § [WHERE conditionlist ];

Back

Advanced Data Updates §

Front

UPDATE command updates only data in existing rows § If a relationship is established between entries and existing columns, the relationship can assign values to appropriate slots § Arithmetic operators are useful in data updates § In Oracle, ROLLBACK command undoes changes made by last two UPDATE statements

Back

WHERE condition •

Front

Specifies the rows to be selected

Back

Special Operators

Front

BETWEEN • Checks whether attribute value is within a range IS NULL • Checks whether attribute value is null LIKE • Checks whether attribute value matches given string pattern IN • Checks whether attribute value matches any value within a value list EXISTS • Checks if subquery returns any rows

Back

COMMIT: Command to save changes •

Front

Syntax - COMMIT [WORK]; • Ensures database update integrity

Back

Authentication

Front

Process DBMS uses to verify that only registered users access the data § Required for the creation tables § User should log on to RDBMS using user ID and password created by database administrator

Back

Deleting a Table from the Database

Front

Can drop a table only if it is not the one side of any relationship § RDBMS generates a foreign key integrity violation error message if the table is dropped

Back

Features of table creating command sequence §

Front

NOT NULL specification § UNIQUE specification §

Back

Primary Key and Foreign Key §

Front

Primary key attributes contain both a NOT NULL and a UNIQUE specification § RDBMS will automatically enforce referential integrity for foreign keys § Command sequence ends with semicolon §

Back

ANSI SQL allows use of following clauses to cover CASCADE, SET NULL, or SET DEFAULT §

Front

ON DELETE and ON UPDATE

Back

Advanced Data Definition Commands §

Front

Keywords use with the command § ADD - Adds a column § MODIFY - Changes column characteristics § DROP - Deletes a column § Used to: § Add table constraints § Remove table constraints

Back

Syntax to delete an index § DROP INDEX

Front

indexname;

Back

Syntax to create SQL indexes § CREATE INDEX

Front

indexname ON tablename(); §

Back

Adding Primary and Foreign Key Designations §

Front

Syntax to add or modify columns § ALTER TABLE tablename § {ADD | MODIFY} ( columnname datatype [ {ADD | MODIFY} columnname datatype ] ) ; § ALTER TABLE tablename § ADD constraint [ ADD constraint ] ;

Back

Changing Column's Data Characteristics §

Front

Use ALTER to change data characteristics § Changes in column's characteristics are permitted if changes do not alter the existing data type § Syntax § ALTER TABLE tablename MODIFY (columnname(characterstic)) ;

Back

ROLLBACK: Command to restore the database •

Front

Syntax - ROLLBACK; • Undoes the changes since last COMMIT command

Back

Comparison Operators: Computed Columns and Column Aliases §

Front

SQL accepts any valid expressions/formulas in the computed columns § Computed column, an alias, and date arithmetic can be used in a single query

Back

Adding a column §

Front

Use ALTER and ADD § Do not include the NOT NULL clause for new column §

Back

Alias

Front

Alternate name given to a column or table in any SQL statement to improve the readability

Back

SQL Indexes §

Front

When primary key is declared, DBMS automatically creates unique index §

Back

Arithmetic operators §

Front

Perform: § Operations within parentheses § Power operations § Multiplications and divisions § Additions and subtractions

Back

Creating Table Structures §

Front

Use one line per column (attribute) definition § Use spaces to line up attribute characteristics and constraints § Table and attribute names are capitalized §

Back

§

Front

Back

Inserting Table Rows with a SELECT Subquery

Front

Used to add multiple rows using another table as source §

Back

Dropping a column §

Front

Use ALTER and DROP § Some RDBMSs impose restrictions on the deletion of an attribute

Back

Common SQL Data Types

Front

Numeric NUMBER(L,D) or NUMERIC(L,D) Character CHAR(L) • VARCHAR(L) or VARCHAR2(L) •DATE Date

Back

Data Manipulation Commands INSERT: Command to insert data into table •

Front

Syntax - INSERT INTO tablename VALUES(); • Used to add table rows with NULL and NOT NULL attributes

Back

SQL Constraints •

Front

Ensures that column does not accept nulls NOT NULL • Ensures that all values in column are unique UNIQUE • Assigns value to attribute when a new row is added to table DEFAULT • Validates data when attribute value is entered CHECK

Back

Categories of SQL function §

Front

Data definition language (DDL) § Data manipulation language (DML) §

Back

Syntax to create table §

Front

CREATE TABLE tablename();

Back

UPDATE: Command to modify data •

Front

Syntax - UPDATE tablename SET columnname = expression [, columnname = expression ] [WHERE conditionlist ];

Back

Composite index: §

Front

Is based on two or more attributes § Prevents data duplication §

Back

Changing Column's Data Type §

Front

ALTER can be used to change data type § Some RDBMSs do not permit changes to data types unless column is empty § Syntax - § ALTER TABLE tablename MODIFY (columnname(datatype)) ;

Back

DROP TABLE

Front

Deletes table from database § Syntax - DROP TABLE tablename ;

Back

SELECT: Command to list the contents •

Front

Syntax - SELECT columnlist FROM tablename ; • Wildcard character (*): Substitute for other characters/command

Back

The Rule of Precedence

Front

Establish the order in which computations are completed

Back

ALTER TABLE

Front

command: To make changes in the table structure

Back

DELETE: Command to delete •

Front

Syntax - DELETE FROM tablename • [WHERE conditionlist ];

Back

The Database Schema §

Front

Logical group of database objects related to each other §

Back

Section 2

(8 cards)

Additional SELECT Query Keywords §

Front

Logical operators work well in the query environment § SQL provides useful functions that: § Counts § Find minimum and maximum values § Calculate averages § SQL allows user to limit queries to entries: § Having no duplicates § Whose duplicates may be grouped

Back

Recursive Joins §

Front

Recursive query : Table is joined to itself using alias § Use aliases to differentiate the table from itself

Back

Listing Unique Values §

Front

DISTINCT clause: Produces list of values that are unique § Syntax - SELECT DISTINCT columnlist FROM tablelist ; § Access places nulls at the top of the list § Oracle places it at the bottom § Placement of nulls does not affect list contents

Back

Grouping Data §

Front

Frequency distributions created by GROUP BY clause within SELECT statement § Syntax - SELECT columnlist FROM tablelist [WHERE conditionlist ] [GROUP BY columnlist ] [HAVING conditionlist ] [ORDER BY columnlist [ASC | DESC]];

Back

HAVING Clause §

Front

Extension of GROUP BY feature § Applied to output of GROUP BY operation § Used in conjunction with GROUP BY clause in second SQL command set § Similar to WHERE clause in SELECT statement

Back

Joining Tables With an Alias §

Front

Alias identifies the source table from which data are taken § Any legal table name can be used as alias § Add alias after table name in FROM clause § FROM tablename alias

Back

Ordering a Listing §

Front

ORDER BY clause is useful when listing order is important § Syntax - SELECT columnlist FROM tablelist [WHERE conditionlist ] [ORDER BY columnlist [ASC | DESC]]; § Cascading order sequence : Multilevel ordered sequence § Created by listing several attributes after the ORDER BY clause

Back

Joining Database Tables §

Front

Performed when data are retrieved from more than one table at a time § Equality comparison between foreign key and primary key of related tables § Tables are joined by listing tables in FROM clause of SELECT statement § DBMS creates Cartesian product of every table in the FROM clause

Back