Introduction to Relational Model Flashcards

1
Q

What are various attribute types in the Relational Model?

A
  • char(n). Fixed length character string, with user-specified length n
  • varchar(n). Variable length character strings, with user-specified maximum length n
  • int. Integer (a finite subset of the integers that is machine-dependent)
  • smallint(n). Small integer (a machine-dependent subset of the integer domain type)
  • numeric(p, d). Fixed point number, with user-specified precision of p digits, with d
    digits to the right of decimal point. (ex., numeric(3, 1), allows 44.5 to be stores
    exactly, but not 444.5 or 0.32)
  • real, double precision. Floating point and double-precision floating point numbers,
    with machine-dependent precision
  • float(n). Floating point number, with user-specified precision of at least n digits
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a Super Key?

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

What is a Candidate Key?

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

What is a Primary Key?

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

What is a Surrogate Key?

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

What is a Composite Key?

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

What is a Secondary Key?

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

What is a Foreign Key?

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

What is a Compound Key?

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

What is Procedural Programming? vs Declarative Programming?

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

What is the domain of an attribute?

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

What are atomic attributes?

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

What is “Select” Relational Operation ?

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

What is “Project” Relational Operation ?

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

What is “Union” Relational Operation ?

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

What is “Difference” Relational Operation ?

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

What is “Intersection” Relational Operation ?

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

What is “Cartesian Product” Relational Operation ?

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

What is “Natural Join” Relational Operation ?

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

What are aggregate operations?

A

◦ SUM
◦ AVG
◦ MAX
◦ MIN

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

What are the basic properties of relations?

A

Relation is a set, so, no ordering, no duplicates.

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

What is a composition of relational operations?

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

How to create a table in SQL?

A

create table instructor (
ID char(5),
name varchar(20)
dept name varchar(20)
salary numeric(8, 2));

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

How to order the display of tuples in SQL?

A
25
Q

How to select Number of Tuples in Output?

A
26
Q

How to deal with Duplicates in SQL?

A

Select distinct - displays unique values
Select all - displays all values including duplicates

27
Q

How to implement Union Set Operation in SQL?

A
28
Q

How to implement Intersect Set Operation in SQL?

A
29
Q

How to implement Difference Set Operation in SQL?

A
30
Q

How to deal with “NULL” values?

A
31
Q

What are some of the frequently used aggregate functions in SQL?

A
32
Q

How to group using an aggregate attribute in SQL?

A
33
Q

How to set conditions of an aggregating attribute in SQL?

A
34
Q

What are Instances in databases?

A

The actual data present in the database at that point of time.

35
Q

What are Turing Complete Languages? Is SQL turing complete?

A

A programming language is considered Turing complete if it can express any computation that a Turing machine can perform. This means that the language provides the necessary constructs and features to implement any algorithm or computation, even if it might not be practical to do so.

SQL is NOT Turning Complete Language

36
Q

What are Integrity Constraints of an attribute?

A

Primary Key, Unique, Not Null, Auto Increment, Foreign Key etc are some of the integrity contraints of an attribute

37
Q

how to check set membership in SQL?

A

Using “in” query

select * from student in (‘CSE’);

38
Q

What are the string operations possible in SQL

A

1) Like - with % wildcard for multiple characters and _ wildcard for single character

39
Q

How to sort the output of a query in SQL?

A

using “order by “ clause.. we could set it to “ASC” or “DESC” or one option per atribute

40
Q

How to create temporary /permanent relations in a database that hides certain information from users

A

Create view v as <query>
one view could be dependent on the other.That is, composition is possible.</query>

41
Q

What are transactions?

A
42
Q

How to evaluate a predicate in SQL

A

Using “Check” clause..

check(semester in (‘Fall’,’Winter’,’Spring’,’Summer’)

43
Q

What is referential integrity? how is it ensured in SQL

A

Foreign Key..

on delete_cascade;
on update cascade;

Alternative actions to cascade: no action, set null, set default.

44
Q

How to create an index in SQL?

A

Create idx_student_id on Student(Student_id)

45
Q

How to create user defined data types in SQL

A

create type Dollars as numeric(12,2) final

46
Q

How to create domains in SQL

A

create domain person_name char(20) not null.

Allows us to specify integrity constraints unlike user defined data types.

47
Q

What are some of large object Types

A
  1. BLOB
  2. CLOB
48
Q

What are forms of authorization on parts of the database?

A
  1. Read
  2. Write
  3. Update
  4. Delete
49
Q

What are forms of auhorization to modify the database schema

A
  1. Index
  2. Resource
  3. Alteration
  4. Drop
50
Q

How to grant authorization in SQL

A

grant <privilege>
on <relation>
to <user></user></relation></privilege>

where
previleges could be select, insert, update,delete, all privileges.

user list could be user id, role or public.

51
Q

How to cancel authorization in SQL?

A

revoke <privilege>
on <relation>
from <user></user></relation></privilege>

52
Q

How to create roles in SQL

A

create role <role_name>
grant <role_name> to Madhan</role_name></role_name>

we could chain the roles
create role <role2>
grant role_name to role2</role2>

Previleges could also be transferred.
grant select on dept to Madhan with grant option

revoke select on dept from Amit cascade

53
Q

How to grant privelege for created foreign keys?

A

grant reference (dept_name) on department to Madhan

54
Q

How are functions defined in SQL?

A

create function dept_count(dept_name varchar(20)) returns integer
begin
declare d_count integger;
select count(*) into d_count
from instructor
whare instructor.dept_name
=dept_name
return d_count;
end

Functions could return a table itself.

55
Q

How to loop in SQL

A

while loop:
while <boolean> do
sequence of statements
end while;</boolean>

repeat loop:
repeat
sequence of statements
until <boolean>
end repeat</boolean>

for loop:
for r as select budget from department
do
set n=n+r.budge
end for;

56
Q

Branching Statements in SQL

A

if-then-else :

if <bool> then
sequence of statements;
elseif <bool> then
sequence of statements;
else
sequence of statements
end if;</bool></bool>

case:

case
when sql-expr =value1 then
sequence of statemetns;
when sql-expr=value2 then
sequence of statemetns;
else
sequence of statemetns;
end case;

57
Q

exception handling in SQL

A

declare out_of_classroom_seats condition
declare exit handler for out_of_classroom_seats
begin
……
signal out_of_classroom_seats
…….
end

58
Q

What are external language routines

A

SQL allows the definition of functions/ procedures in an imperative programming language like Java, C, C# etc which can be invoked from SQL queries.
create procedure dept _coutn_proc(in dept_name varchar(20),out count integer)
Language C
external name ‘/usr/avi/bin/dept_count_proc/

create function dept_count(dept_name varchar(20)) returns integer
language C
external name ‘/usr/avi/bin/dept_count’