Chapter 4: Advanced SQL Flashcards

1
Q

Explain char vs varchar

A

char(m): has a fixed length

varchar(m): variable length that can increase or decrease as needed

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

What is the purpose of integrity constraints?

A

By putting rules (constraints) on attributes/data you can ensure that said data contains the correct value.
-guard against accidental damage to the database by ensuring authorized changes to DB don’t result in a loss of data consistency

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

What are some built in data types for SQL

A

date: (4-digit) year, month, and date
time: time of day in hours, minutes and seconds
timestamp: date plus time of day
interval: period of time
- date/time/timestamp minus another gives an interval
- intervals can be added to date/time/timestamp values

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

How can a user define a data type in SQL?

A

CREATE TYPE

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

How can a user define a domain in SQL?

A

CREATE DOMAIN

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

types vs domains in SQL

A

they are similar

  • domain: names, user-defined set of valid values
  • type: attribute that specifies the type of data of any object
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are domain constraints?

A
  • most elementary form of integrity constraint

- tests values inserted in DB, and test queries to make sure comparisons are valid

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

What is a BLOB?

A
  • binary large object
  • when a piece of data is very large and is stored as its binary representation (looking at bits)
  • this is done with non-ascii data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a CLOB?

A
  • character large object
  • large piece of data that is text, is looked at and stores through bytes
  • done with ascii stores of text
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How are BLOBs and CLOBS stored in tables?

A

They are stored as pointers to the actual data

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

What is the benefit of having constraints at the table/schema level?

A

Constraints specified at the table/schema level carry over to all other areas and people who use them
-you do not have to write the constraints anywhere else in the application program once it is defined at the schema level

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

What are examples of constraints on a single relation?

A
  • not null
  • primary key
  • unique
  • check(P), where P is a predicate
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does NOT NULL do?

A

sets an attribute with the constraint that it cannot be null

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

What does PRIMARY KEY do?

A

sets an attribute as the primary key, also primary key’s cannot be null

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

What does UNIQUE do?

A

sets a set of attributes to form a candidate key

-candidate key’s can be null

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

What does CHECK(P) do?

A

allows for certain domains to be restricted to certain values

17
Q

What is referential integrity?

A

When the integrity constraints of one attribute in one table are passed along to another via an relation between two tables
-like how foreign key’s of a child table have the same integrity constraints as they do in the the parent table

18
Q

What do the three key clauses do in the CREATE TABLE statement?

A
  • primary key clause: lists attributes that comprise the primary key
  • unique key clause: lists attributes that comprise a candidate key
  • foreign key clause: lists the attributes that comprise the foreign key and the name of the relation referenced by the foreign key
19
Q

What is an assertion?

A
  • a predicate expressing a condition that we wish the database to always satisfy
  • CREATE ASSERTION CHECK
  • when assertion is made, system checks it for validity and tests it again on every update that may violate the assertion