• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/43

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

43 Cards in this Set

  • Front
  • Back

Name five types of constraints.

1. Primary Key


2. Foreign Key


3. General table constraints


4. Domain constraints.


5. Assertions

Name two characteristics about primary key constraints.

1. The attributes of the primary key cannot be null.


2. The primary key must be unique.

Name two ways to create a primary key constraint.

1. CREATE or ALTER TABLE statement


eg. PRIMARY KEY




2. Selecting the attribute(s) and selecting primary key in the context menu.

What is a foreign key constraint?

Table R contains a FK on attr {a} that ref. table S.




1. Values for {a} in R must also exist in S except that if {a} is not part of the primary key of R it may be null.




2. There may be values for {a} in S that are not in R.

How do you specify actions for foreign keys?

branchName CHAR(20) DEFAULT 'Granville'

FOREIGN KEY (branchName) REFERENCES Branch

ON DELETE SET DEFAULT


ON UPDATE CASCADE

What happens in a cascading deletion or update if a violation is thrown?

The entire transaction is aborted.

What are the four actions possible for updates and deletions?

1. NO ACTION

2. CASCADE


3. SET NULL


4. SET DEFAULT

How can you reference non-primary keys in another table?

Specify a list of attributes as UNIQUE (candidate key).

What is a general table constraint?




How is it defined?

A constraint over a single table.




Defined by CHECK keyword.

What is the limitation for SQL server check constraints?

They are limited to scalar (single-valued) expressions.

What is a UDF? What is their purpose?

User Defined Function.




CHECK constraints can run against them (if they return a scalar value).

Name three benefits of UDFs.

1. Modular programming.


2. Faster execution.


3. Reduced network traffic.

Write a UDF.

CREATE FUNCTION name()


RETURNS int


AS


BEGIN


DECLARE @result int


....


RETURN @result


END

What statement is used to create a new domain?

CREATE DOMAIN.

What four things are required for a domain?

1. Name


2. Base Type


3. A restriction (CHECK statement)


4. Default Optional Value

Are domains attached to individual table schemata?

No. They are part of the DB schema however.

What is this domain?




CREATE DOMAIN minorAge INTEGER DEFAULT 10


CHECK (VALUE > 0 AND VALUE <=18)

A domain for minors, who have ages between 0 and 18.

Can distinct types be compared?

No. Types are distinct so values of different types cannot be compared.

Write a create type statement 'ID' as an integer.

CREATE TYPE IS AS INTEGER

Name 8 useful base types.

1. bigint


2. bit


3. date


4. char(n)


5. float


6. real


7. int


8. nvarchar(n | max)

What is an assertion?

A table constraint that apply to only one table.

When are assertions tested?

Whenever the DB is updated.

Does Transact-SQL implement assertions?

No.

CHECK ASSERTION assetCoverage


CHECK (NOT EXISTS


SELECT *


FROM Branch B


WHERE assets <


(SELECT SUM(A.balance)


FROM Account A


WHERE A.branchName = B.branchName)))

Check that a branch's assets are greater than the total account balances held in the branch.

What kind of constraints can't be modeled with table constraints or assertions?

Participation constraints.

What is a trigger?

A procedure that is invoked by the DBMS as a response to a specified change.

What is different, in general, in triggers vs constraints?

Constraints only reject transactions, triggers carry out actions.

What are the three components to a trigger?

1. Event


2. Condition


3. Action

CREATE TRIGGER reminder1


ON Sales.Customer


AFTER INSERT, UPDATE


AS RAISERROR('Notify Customer Relations', 16, 10)

Write a message when a customer is added or updated.

What is the general SQL syntax for a trigger?

CREATE TRIGGER trigger_name


ON {table | view}


{ FOR | AFTER | INSTEAD OF } { INSERT, UPDATE, DELETE }


AS {sql_statement}

What is the difference between AFTER and INSTEAD OF for triggers?

AFTER executes after the transaction, INSTEAD OF replaces the transaction.

What is the order for the AFTER trigger?

1. Enforce constraints


2. Enforce foreign key constraints


3. Create inserted and deleted tables


4. Execute the triggering statement


5. Execute after trigger

What is the inserted table? Deleted table?

Inserted table contains records that were inserted by a transaction.




Deleted table contains records that were deleted by a transaction.

What is a drawback of triggers?

They carry overhead. PKs, FKs and simple CHECK constraints should be used where possible

What is an index?

An index is a data structure that provides efficient access to records.

What is a table scan?

An inefficient lookup of table records.

Typically OLTP indexes are variations on which two data structures?

1. Hash tables


2. (Binary) search trees

What is a hash index? What is a drawback?

A hash table where the hash function maps attribute values to record IDs.




They cannot be used for range searches.

What is a tree index? In practice, what data type is used?

Directs searches in much the same way as a binary search tree.




B-trees (n-ary) trees.

How is n derived in a b-tree?

The size of the attribute values, record IDs and disk pages.

What are the benefit / drawback of tree indexes?

1. Supports range searches


2. Not as fast as hash indexes

What is a clustered index? How many are allowed?

A clustered index is one where the underlying data file is sorted on the index search key.




One.

What is the benefit of indexes? Drawback?

1. Increase the efficiency of operations requiring look-up of attribute values.


2. Index management.