Database-chap 8 Flashcards

SQL (31 cards)

1
Q

SQL functions fit into two broad categories

A

Data definition language
Data manipulation language

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

Data definition language

A

SQL includes commands to:
-Create database objects, such as tables, indexes, and views
-Define access rights to those database objects

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

Data manipulation language

A

Includes commands to insert, update, delete, and retrieve data within database tables

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

Data Types

A

Data type selection is usually dictated by nature of data and by intended use

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

SQL Constraints

A

-NOT NULL constraint
Ensures that column does not accept nulls
-UNIQUE constraint
Ensures that all values in column are unique
-DEFAULT constraint
Assigns value to attribute when a new row is added to table
-CHECK constraint
Validates data when attribute value is entered e.g min order

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

SQL Indexes

A

When primary key is declared, DBMS automatically creates unique index

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

Create index

A

Using CREATE INDEX command, SQL indexes can be created on basis of any selected attribute

CREATE UNIQUE INDEX indexname
ON tablename (column1);

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

Data Manipulation Commands

A

Adding table rows
Saving table changes
Listing table rows
Updating table rows
Restoring table contents
Deleting table rows
Inserting table rows with a select subquery

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

Adding Table Rows notice that:

A

-Row contents are entered between parentheses
-Character and date values are entered between apostrophes
-Numerical entries are not enclosed in apostrophes
-Attribute entries are separated by commas
-A value is required for each column
-Use NULL for unknown values

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

Insert

A

Used to enter data into table
Syntax:
INSERT INTO TABLE VALUES (value1, value2, … , valuen);

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

Commit

A

Will permanently save any changes made to any table in the database

COMMIT[WORK];

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

Changes made to table contents are not physically saved on disk until, one of the following occurs:

A

-Database is closed
-Program is closed
-COMMIT command is used

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

SELECT

A

-Used to list contents of table
Syntax:
SELECT columnlist FROM tablename;

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

UPDATE

A

Syntax:
UPDATE tablename SET columnname = expression columname = expression columnname WHERE conditionlist];

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

ROLLBACK

A

-Used to restore database to its previous condition
-Only applicable if COMMIT command has not been used to permanently store changes in database

Syntax:
ROLLBACK;

COMMIT and ROLLBACK only work with data manipulation commands that are used to add, modify, or delete table rows

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

Delete

A

Deletes a table row
Syntax:
DELETE FROM tablename[WHERE conditionlist ];

17
Q

Inserting Table Rows with a Select Subquery

A

INSERT
-Inserts multiple rows from another table (source)
-The values returned by the SELECT subquery must match the attributes and data types of the table in the INSERT statement
-Uses SELECT subquery
Query that is embedded (or nested) inside another query
Executed first

18
Q

Selecting Rows with Conditional Restrictions

A

Syntax:
SELECT columnlist
FROM tablelist
[ WHERE conditionlist ] ;

19
Q

Selecting Rows with Conditional Restrictions

A

Syntax:
SELECT columnlist
FROM tablelist
[ WHERE conditionlist ]

20
Q

Arithmetic Operators: The Rule of Precedence

A

-Perform operations within parentheses
-Perform power operations
-Perform multiplications and divisions
-Perform additions and subtractions

21
Q

Special Operators

A

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

22
Q

Advanced Data Definition Commands

A

All changes in table structure are made by using ALTER command
Followed by keyword that produces specific change
Following three options are available:
ADD
MODIFY
DROP
ALTER TABLE PRODUCT
{ADD PROD_NAME};

23
Q

Changing a Column’s Data Type

A

ALTER can be used to change data type
ALTER TABLE PRODUCT
MODIFY (V_CODE CHAR(5));

24
Q

Dropping a Column

A

Use ALTER to drop column
-Some RDBMSs impose restrictions on the deletion of an attribute
E.G. ALTER TABLE VENDOR
DROP COLUMN V_ORDER;

25
Copying Parts of Tables
SQL permits copying contents of selected table columns so that the data need not be reentered manually into newly created table(s) CREATE TABLE PART(
26
Adding Primary and Foreign Key Designations
When table is copied, integrity rules do not copy, so primary and foreign keys need to be manually defined on new table Syntax: ALTER TABLE tablename ADD PRIMARY KEY(fieldname); For foreign key, use FOREIGN KEY in place of PRIMARY KEY
27
Deleting a Table from the Database
DROP Deletes table from database Syntax: DROP TABLE tablename; DROP TABLE PART;
28
Advanced Select Queries
SQL provides useful functions that can: Count Find minimum and maximum values Calculate averages
29
Grouping Data
SELECT PROD_CODE, AVG(PROD_PRICE) FROM PRODUCT GROUP BY PROD_PRICE
30
HAVING clause
Applied to the output of a GROUP BY operation SELECT PROD_CODE, AVG(PROD_PRICE) FROM PRODUCT GROUP BY PROD_PRICE HAVING AVG (PROD_PRICE) < 10;
31
ORDER BY clause
-Used to sort output of SELECT statement -Can sort by one or more columns and use either an ascending or descending order