Ch 3: Intro to SQL Flashcards

1
Q

3 Basic

Integrity Constraints

that can be defined in a Relation

A

primary key( Aj1, Aj2, … , Ajm)

Specifies given attributes as the primary key (all together)

Primary key attributes must be non-null and unique

foreign key( Ak1, Ak2, … , Akn) references Relation_S

Attributes must be the Primary Key of some tuple in the other relation

not null

Added to a specific attribute

example: name varchar(20) not null,

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

Important Parts/Features

of the SQL Language

(7)

A
  • Data Definition Language (DDL)
  • Data Manipulation Language (DML)
  • Integrity
  • View Definition
  • Transaction Control
  • Embedded SQL/Dynamic SQL
  • Authorization
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

SQL Features:

Data Definition Language( DDL )

A

Commands for

  • defining relational schemas
  • modifying relational schemas
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

SQL Features:

Data Manipulation Language( DML )

A

Commands for:

  • Querying data from the database
  • Insert/delete tuples
  • Modify tuples
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

SQL Features:

Integrity

A

Part of the DDL part of SQL

SQL provides commands for specifying Integrity Constraints

Also prevents updates from violating Integrity Constraints

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

SQL Features:

View Definition

A

SQL includes commands for

Defining Views

Part of being DDL

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

SQL Features;

Transaction Control

A

Commands for specifying the

beginning and end

of transactions

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

SQL Features:

Embedded SQL/Dynamic SQL

A

Defines how SQL statements can be

embedded within

general purpose languages

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

SQL Features:

Authorization

A

Includes commands for specifying

Access Rights

to relations and views

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

Two Aspects of

SQL as a Language

A

The SQL Language provides functionality for:

  • Data Definition (DDL)
    • Declaring and modifying database schemas
  • Data Manipulation (DML)
    • Operations for working with actual data
    • Queries and modifications of tuples
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Three kinds of Relations

in SQL

A
  • Stored Relations
    • Called Tables
    • kind of relation we deal with normally
    • relations that are stored in the database
  • Views
    • relations defined by a computation
    • not stored
    • constructed in whole or part when needed
  • Temporary Tables
    • constructed by the SQL language when executing queries/modificatons
    • thrown away after query, not stored
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

SQL Statement

to Define a Relation Schema

A

CREATE TABLE

  • Gives a name for the table, its attributes and their data types
  • Also allows declaring a key, or several, for a relation
  • Allows constraint and index declarations, among others
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

SQL Primitive Data Types

A

CHAR(n), VARCHAR(n)

BIT(n), BITVARYING(n)

BOOLEAN

INT, or INTEGER

FLOAT, or REAL, DOUBLE PRECISION

DECIMAL( n, d)

DATE

TIME

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

SQL Example:

Declare this schema in SQL:

Movies( title: string, year:integer, genre: string)

A

CREATE TABLE Movies (

title CHAR(100),

year INT,

genre CHAR(10)

);

end with semicolon, each attribute has the form:

name TYPE

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

The SQL DDL

allows Specification of

What Relation Properties?

A
  • Schema for each relation
  • Types of Values associated with each attribute
  • Integrity Constraints on values
  • Set of Indices to be maintained for each relation
  • Security and Authorization info for each relation
  • Physical Storage Structure of each relation on disk
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Basic SQL Table Commands (5)

A

CREATE TABLE r( A1 D1, A2 D2, … );

creates a table with the specified attributes and types

DROP TABLE r;

remove a table from the database

ALTER TABLE r ADD a d;

add the attribute ‘a’ with type ‘d’ to the table

ALTER TABLE r DROP a;

remove attribute ‘a’ from the table

DELETE FROM r;

INSERT INTO r values( v1, v2, … , vn);

add a tuple into the table r

17
Q
A