0% found this document useful (0 votes)
29 views13 pages

Very Short Notes

Uploaded by

Tanveer Abbas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views13 pages

Very Short Notes

Uploaded by

Tanveer Abbas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Very Short Notes Functional dependency:

Functional dependency:
if each value of A in R is associated with exactly one value of B in R;
Notation:
Determinant:
Set of attributes on left side are called determinant (A).
Dependents:
Set of attributes on right side are called dependents (B).
Super keys: (Columns) (uniquely)
A minimal super key is the candidate key.

Inference Rules:
Called inference axioms or Armstrong axioms.
Names Rules
1. Reflexivity: If B is a subset of A, then A B.
This also implies that A A always
holds. Functional dependencies of
this type are called trivial
dependencies.
2. Augmentation: If we have A B then AC BC
3. Transitivity: If we have A B and B C then A
C.
4. Additivity of Union: If we have A B and A C then A
BC.
5. Projectivity or Decomposition: If we have A BC and A B then
A C.
6. Pseudo transitivity: If we have A B and CB D then
AC D.
Two type of data dependency: i): Row Level ii): Column Level
Three type of normalization.
1st Normal Form (Tuple: Atomic value, No multivalued)
2nd Normal Form (fully functionally dependent, No partial Depedency)
3rd Normal Form (Transitive Dependency,
BCNF: Boyce – Codd Normal Form ( candidate key)
4NF: deals with multivalued dependency.
5NF: deals with possible loss less decompositions.
DKNF: Domain Key Normal Form
reduces further chances of any possible inconsistency.
Fields mean columns.
Field is the smallest unit of application data.
Data types:
1. the structure defined for placing data in the attributes
2. Set of values along with the operations that can be performed.
Data Types Size
VARCHAR2(Size) 1 to 32767
VARCHAR
CHAR(size) 1 to 32767
NUMBER (p, s) -84 to 127
LONG 32760
DATE 4712 to 9999
RAW(size) 32767
LONG RAW 32760
BLOB 4gigabytes
Denormalization: move from higher to lower normal forms.
De-normalization: Merging
Partitioning: Split
There are two types of partitioning:-
1. Horizontal Partitioning (Rows)
2. Vertical Partitioning (Columns)
Horizontal Partitioning
Table is split on the basis of rows, which means a larger table is split into
smaller tables.
Horizontal partitioning types:
1. Range partitioning (range is imposed)
2. Hash partitioning (particular algorithm is applied)
3. List partitioning (values are specified, no range involved)
Range partitioning become unbalanced
Hash Partitioning: reduces the chances of unbalanced
partitions.
Replication:
copying a portion of the database.
Clustering Files:
To place records from different tables to place in adjacent physical locations
called clusters.
Rules of SQL Format: read, write, and remove.

SQL Commands:
Two commands:
1. DDL: Data Definition Language (create , alter , Drop and
destroy/delete)
2. DML: Data Manipulation Language (insert, retrieve , deletion and
modify)
3. DCL: Data Control language (GRANT and REVOKE)
DDL: CADDD
DML: IRDM
Following are the rules for writing the commands in SQL:-
•Reserved words are written in capital like SELECT or INSERT.
• User-defined identifiers are written in lowercase
• Identifiers should be valid, which means that they can start with @,
alphabets ,or with numbers.
The maximum length can be of 256.
[ ] it is optional.
{ } it is necessary.
| choice.
Data Types in SQL Server:

1. Integer

Integers
Name Range
Biggint -2 -9,223,372,036,854,775,808) to 261
61

- 1 (9,223,372,036,854,775,808)
Int -231 -2,147,483,648) to 231 - 1
(2,147,483,648)
Smallint -215 (-32,768) to 215 - 1 (32,767)
Tinyint 0 to 255

2. bit
Integer data with either a 1 or 0 value.

3. Decimal and Numeric


• Decimal
Fixed precision and scale numeric data from -1038 +1 through 1038 –1.
• Numeric
Functionally equivalent to decimal.

4. Text:
It handles the textual data.
Following are the different data types.
• Char: By default 30 characters, max 8000
• Varchar: Variable length text, max 8000
• Text: Variable length automatically
• nchar: nvarchar, ntext

5. Money:
: handles monetary data
o smallmoney: 6 digits, 4 decimal
o money: 15 digits, 4 decimal

6. Floating point
o Float
o Real

7. Date
o Smalldatetime
o datetime
Other name of data dictionary is metadata.
Two types of DML:
i): Procedural: (What to do and how to do)
ii): Nonprocedural: (What to do)
Syntax: CREATE DATABASE atabasename;
Alter Table Statement: (Columns)( make changes in the definition of a table
already).
We cannot add, delete or modify: more than one column at a time.
TRUNCATE DELETE DROP
It is used to delete all It is used to delete one It is used to drop the
the rows of any table or many records/row. complete table from the
but rows would exist. database
Drop table: then table should be fully delete.
Truncate table: then only data inside the table should be deleted.
SQL is a ……….language?
i) non-procedural ii) Procedural

Insert Statement: (DML)


i): Row/Record/Tuple ii): INTO
The INSERT statement has two variations.
1. The INSERT...VALUES: to insert one record.
2. The INSERT...SELECT: to insert multiple records
Unlisted columns are set to null.

Select Statement: (DML)


1. Rows
2. Columns
The basic SELECT statement has 3 clauses:
• SELECT
• FROM
• WHERE
When we miss to write WHERE clause with SELECT: Select the all rows.
When we miss to write WHERE clause with DELETE: Delete the all rows.

The WHERE clause is optional.


The SELECT clause is mandatory.
Predicate: (logical expression)

BETWEEN Operator
allows you to retrieve values within a specific range.

IN operator:
reduce the need to use multiple OR conditions.

Like Operator
wildcards in the where clause.
Perform: pattern matching.
1. %: Match string of any length (including zero length)
2. _ Match a single character

ORDER BY clause:
to sort the records in your result set.
The ORDER BY clause sorts the result set based on the …..specified?
1. Columns
2. Rows
ASC indicates ascending order. (By Default)
DESC indicates descending order.
ORDER by clause only used with select.

Functions in SQL
one-word command that return a single value.
The value of a function can be determined by input parameters.
Functions are categorized as under:
– Mathematical (ABS, ROUND, SIN, SQRT)
– String (LOWER, UPPER, SUBSTRING, LEN)
– Date (DATEDIFF, DATEPART, GETDATE())
– System (USER, DATALENGTH, HOST_NAME)
– Conversion (CAST, CONVERT)
Aggregate Functions:
Functions that operate on a set of rows and return a single value.
Aggregate function can be a function such as AVG, SUM, COUNT, MIN or
MAX.
Cartesian product:
A Cartesian join gives a Cartesian product.
A Cartesian join is when you join every row of one table to every row of
another table
Cartesian Product
 Inner join ( Rely on common attributes)
 Outer Join ( Rely on NULL values)
 Full outer join (rows without a match appear in the result)
 Semi Join (Two operation: inner join+ project)
 Natural Join
The queries are evaluated: in the reverse order,
1. the inner most is evaluated first,
2. then the outer one
3. finally the outer most.
Type of user interface: (Two)
• Text based (UI)
• Graphical User Interface (GUI) most commonly called as Form
Type of users Type of forms
Two Two
 Beginners (What and How)  Browser Based (Web based)
(task-oriented)
 Intermediate (What) (use the  Non-Browser/Simple
index as their primary access  Visual Basic, Developer, MS
mechanism) Access

 Typical media available are:


 Cache
 Main memory
 Flash Memory
 Magnetic disk
 Optical storage (CD or DVD)
 Tape storage

Cache
Cache: Pronounced cashe.
Two types of caching are commonly used in personal computers:
1. Memory caching (RAM)
2. Disk caching
SRAM: high-speed static RAM (SRAM)
DRAM: slower and cheaper DRAM
Level 1 (L1) cashes:
Internal caches.
Level 2 (L2) cache:
External cache
Flash memory is a form of EEPROM.
1. Non-volatile
2. Stores information on a silicon chip
FAMOS: Floating-Gate Avalanche-Injection Metal Oxide Semiconductor.
Floppy Disk: A typical 5¼-inch floppy disk can hold 360K or 1.2MB
(megabytes).
3½-inch floppies normally store 720K, 1.2MB or 1.44MB of data.
Hard disks can store anywhere from 20MB to more than 10GB.
Optical disks come in three basic forms:
1. CD-ROM:
2. WORM
3. Erasable Optical (EO)
CD-ROM: Most optical disks are read-only.
WORM: Stands for write-once, read-many.
RAID: Redundant Array of (Independent ) or Inexpensive Disks.
One sector (512 bytes) or as large as several megabytes (1MB).
key trAnsformation is known as:
A. Direct
B. Hash
Type of Direct Access File Organization: (Two)
1. Indexed Sequential
2. Direct File Organization
Double file access: (index + data).
Two types of indexes:
1. The exhaustive type
2. The partial type
An indexed sequential file must have at least one key.
The first (primary) key is always numbered 0.
Indexed sequential file can have up to 255 keys
No more than 7 or 8 keys.
A good hash function gives an average-case lookup.
The worst hash function maps all keys to the same address/bucket.
The best hash function maps all keys to distinct addresses.
Hashing Algorithms: (Two types)
1. Prime division/remainder
2. Folding method
Perfect hashing function: (one-to-one mapping) k to integers in (1,m).
Simplest re-hashing functions is +1 (or -1).
An index on a table is a disk-based data structure.
Index Classification:
 Clustered vs. Un-clustered Indexes
 Single Key vs. Composite Indexes
 Tree-based, inverted files, pointers

o Two types of primary index:

1. Dense index (some of the key value)


2. Sparse index

Index support Range selections:


1. <, >
2. <=
3. >=
4. BETWEEN)
To locate a record, we find the index record:
Largest key values ≤ search key value.
No overflow blocks: we can use binary search.
as 1log2(b) blocks (as many as 7 for our 100 blocks).
Overflow blocks: then sequential search typically used, reading all b index
blocks
Ways to create a new view in your database: (Two)
Types of views?
ANS:
1. Materialized View
2. Simple Views
3. Complex View
4. Dynamic Views.

Deleting Views: (DROP VIEW command)


Indexes: cannot be accessed directly using a SELECT statement.
Materialized views: can be accessed directly using a SELECT statement
ACID: Atomicity, Consistency, Isolation, and Durability.
A transaction can thus end/termination in two ways:
1. Commit (successful execution)
2. Rollback or Abort (Error)

Transaction: ( series)
a set of actions that are partially ordered.
Denote the transactions:
A transaction T reading an object O as
Reading: RT (O);
Writing: WT (O).
Strict Two-Phase Locking (Strict 2PL): Has two rules.
Deadlock:
A cycle of transactions waiting for locks to be released is called a
deadlock.
The lower the timestamp, the higher the transaction's priority
The oldest transaction has the highest priority.
Deadlock Prevention
Wait-die: Ti has higher wait Aborted
priority
Wound-wait Ti has higher abort Tj Ti waits
priority
In the wait-die Lower PT Can never wait Higher PT
scheme
In the wound-wait Higher Pt Can never wait Lower PT
scheme:
Wait-die scheme is non-preemptive.
Wound-wait scheme is preemptive.
Wait for graph:
The lock manager maintains a structure called a waits-for graph.
Conservative 2PL: (A variant of 2PL)
Write Sequence or operation Data Entry in log file will be
X = X + 10 <Tn, X, 33>
 Transaction Record:
 <T, starts>
 <T, commits> or <T, aborts>
 Forward order: < Tr, begin> and < Tr, commit> Redone
 Reverse Order: < Tr, begin > and < Tr, abort > or < Tr, begin >
Undone
 The deferred update approach stores only the new value.
 The immediate update approach stores the previous as well as new
value.
The compatibility of locks means: that if the two locks from two different
transactions may exist at the same time.
Interaction is in the process of changing system state.
Transaction isolation levels.
Two primary modes for taking locks:
1. Optimistic
2. Pessimistic.
Pessimistic locking guarantees that the first transaction can always apply a
change to the data it first accessed.
Optimistic locking mode: the first transaction accesses data but does not take
a lock on it.
Types of Locks:
1. Shared 2. Update 3. Exclusive locks
Q: Shared locks are used when data is …..(usually in pessimistic locking
mode).
a. Read b. Write
Deadlock is a situation when two transactions are waiting for each other to
release a lock.
Wait – for Graph:
Q: ….. is used for the detection of deadlock.
ANS:
Wait – for Graph
Arrowhead represents that a transaction has locked a particular data item.
Two Phase Locking:
 The locks are granted and released in two phases, the growing and
shrinking phase
 Finer the granularity more concurrency but more overhead
When a lock at lower level is applied, compatibility is checked upward.
The granularity of locks: how much of the data is locked at one time.

You might also like