RDBMS Notes
RDBMS Notes
⮚ SCHEMA vs INSTANCE:
⮚ METADATA:
⮚ DATA DICTIONARY:
⮚ SYSTEM CATELOG:
⮚ Structured Query Language (SQL) as we all know is the database language by the use of
which we can perform certain operations on the existing database and also we can use this
language to create a database. SQL uses certain commands like Create, Drop, Insert, etc. to
carry out the required tasks.
⮚ These SQL commands are mainly categorized into following categories as:
SQL
COMMANDS
DDL
COMMANDS
⮚ CREATE Command:
● The CREATE TABLE statement is used to create a new table in a database.
● A table name should be Unique.
● Each column has minimum three attributes: Name, Data type and Size for that column.
Syntax:
● A table name and column name must start with alphabet, must not match with reserved
keywords, and it can be combination of A-Z, a-z, 0-9, and '_' (underscore) having
maximum length up to 30 characters.
● Each column definition is separated by from other by a ‘,' (comma).
● The entire SQL statement is terminated with ' ; ' (semi colon).
Example: Create a ‘Faculty’ table having columns (FacultyName, Department and Experience) as
described below:
Column
Datatype Size
Name
F_Name Varchar2 30
F_Dept Varchar2 15
Experience Number 2
Input command:
Output:
Table Created.
⮚ DESC or DESCRIBE:
● Once the table is created, there is a need to verify whether a table has been created
according to requirements. For this purpose ‘describe’ command can be used as follow:
Syntax:
DESC tableName;
OR
DESCRIBE tableName;
Input Command:
Output:
FACULTYNAME VARCHAR2(20)
DEPARTMENT VARCHAR2(20)
EXPERIENCE NUMBER(2)
⮚ ALTER command:
⮚ RENAME command:
⮚ DROP command:
⮚ TRUNCATE command:
DML
COMMANDS
⮚ INSERT command:
⮚ UPDATE command:
⮚ DELETE command:
⮚ DQL COMMAND:
⮚ SELECT command:
⮚ TCL COMMANDS:
TCL
COMMANDS
⮚ COMMIT command:
o Implicit commit
o Explicit commit
⮚ SAVEPOINT:
⮚ ROLLBACK:
o Complete rollback
o Partially rollback
⮚ DCL COMMANDS:
DCL
COMMANDS
GRANT REVOKE
⮚ GRANT command:
⮚ REVOKE command:
⮚ OPERATORS:
⮚ FUNCTIONS:
o Aggregate:
o Scalar:
▪ Number
▪ Character
▪ Date
▪ Conversion
Constraints:
SQL constraints are used to specify rules for the data in a table. Constraints are used to limit
the type of data that can go into a table.
Ensures validity, correctness and to consistency of data in a database.
NOT NULL
Domain integrity
constraints
Check
Constraints
Entity Integrity
Primary Key
Key Constraints
Unique Key
Referencial Foreign key
Integrity constraint
Entity Integrity:
Restricts the values in row of an individual table.
Domain:
Unique set of values that can be assigned to an attribute in a database.
Domain Integrity: NOT NULL, CHECK
Specifies that the value of each column must belong to the domain of that column.
KEY Constraints: Primary Key, Unique Key
Ensures that there must be some way to distinguish two different rows of the same table
uniquely.
Referential Integrity: Foreign Key
Specifies that a row in one table that refers to an existing row of another table.
Requires that values in a foreign key column must either be present in the primary key that
is referenced by the foreign key.
NOTE: Constraints can be applied using CREATE TABLE statement while creating a new table
or using ALTER TABLE statement to modify or add constraints in an existing table.
Level of Constraints
Column Level
Defined along with column definition
Table Level
Defined after defining all the columns of a table
NOT NULL constraint is "not allowed" to defined at table level
Keys:
A key in DBMS is an attribute or a set of attributes that help to uniquely identify a tuple (or
row) in a relation (or table).
Key Attribute Minimal number of attribute(s) which uniquely identifies all records in a
relation
Candidate If no. of key attributes >1 then all are called candidate keys
Key
Primary Key From candidate key(s) any 1 choosen by database designer as primary key
Super Key Super set of all key(s). All possible combination of attribute(s) which uniquely
identifies all records in a relation
Example:
Student:
Key Attributes:
KA1: Enrollment
KA2: VoterID
KA3: UID
KA4: Last_Name, DOB
KA Set: {Enrollment, VoterID, UID, (Last_Name, DOB) }
CK = KA Set
PK= Any 1 KA is selected from KA Set (eg. PK = Enrollment)
AK Set= CK – PK (eg. AK Set = { VoterID, UID, (Last_Name, DOB)}