Class XII IT Notes
Class XII IT Notes
Data is a collection of raw facts which have not been processed to reveal useful information.
Information is produced by processing data.
Collection of related data that has been recorded, organized, and made available for searching is
called a Database.
In database approach, a single repository of data is maintained which is accessed by different users
as per their needs.
Some examples of DBMS are – MySQL, Oracle, DB2, IMS, IDS etc.
Relational Database
Relational database, developed by E.F Codd at IBM in 1970, is used to organize collection of data
as a collection of relations where each relation corresponds to a table of values. Each row in the
table corresponds to a unique instance of data and each column name is used to interpret the
meaning of that data in each row.
In relational model,
• A row is called a Tuple.
• A column is called an Attribute.
• A table is called as a Relation.
• The data type of values in each column is called the Domain.
• The number of attributes in a relation is called the Degree of a relation.
• The number of rows in a relation is called the Cardinality of a relation.
• Relation Schema R is denoted by R (A1, A2, A3 …, An) where R is the relation name and A1,
A2, A3 …, An is the list of attributes.
• Relation State is the set of tuples in the relation at a point in time. A relation state r of the
relation schema R (A1, A2, A3 …, An), denoted r(R) is a set of n-tuples r = {t1, t2, …, tm}, where
each n-tuple is an ordered list of values t = <v1, v2, ..., vn>, where vi is in the domain of Ai or
is NULL. Here n is the degree of the relation and m is the cardinality of the relation.
• The degree of the EMPLOYEE relation is 5 as there are five attributes in this relation.
• The cardinality of the EMPLOYEE relation is 3 as there are three tuples in this relation.
• Relation Schema – EMPLOYEE (Name, Employee_ID, Gender, Salary, Date_of_Birth)
• Relation State – {<Neha Mehta, 1121, Female, 20000, 04-03-1990>,
<Paras Bansal, 2134, Male, 25000, 19-10-1993>,
<Himani Verma, 3145, Female, 20000, 23-11-1992>}
• Key Constraint:
(i) Superkey is a set of attributes in a relation, for which no two tuples in a relation state
have the same combination of values. Every relation must have at least one superkey
which is the combination of all attributes in a relation. Thus, for the EMPLOYEE relation,
following are some of the superkeys:
(ii) Key is the minimal superkey, which means it is the superkey of a relation from which
if any attribute is removed then it no longer remains a superkey.
For example, the superkey {Name, Employee_ID, Gender}is not a key as we can remove
Name and Gender from this combination and then what is left {Employee_ID} is still a
Superkey. Now {Employee_ID} is a key as it is a superkey as well as no more removals are
possible. A relation may have more than one key. Consider the relation PERSON with the
following schema: PERSON (Aadhar_number, PAN, Voter_ID_cardno, Name, Date_of_birth,
Address). This relation has three keys namely: {Aadhar_number}, {PAN}, {Voter_ID_no} as
every individual in India has a unique Aadhar card number, PAN as well as Voter ID card
number.
(iii) Candidate key: A key as described above is called candidate key of the relation. For
example, the PERSON relation has three candidate keys as discussed above.
(iv) Primary Key: One of the candidate keys may be designated as Primary key. Primary
key is used to identify tuples in a relation. If a relation has many candidate keys it is
preferable to choose that one as primary key which has least number of attributes. Primary
key is usually underlined in the schema of the relation. For example, in the relation
schema: PERSON (Aadhar_number, PAN, Voter_ID_cardno, Name, Date_of_birth, Address),
Aadhar_number is the primary key.
• Null Value Constraint: Sometimes it is required that certain attributes cannot have null
values. For example, if every EMPLOYEE must have a valid name then the Name attribute
is constrained to be NOT NULL.
• Entity Integrity Constraint: This constraint specifies that primary key of a relation cannot
have null value. The reason behind this constraint is that we know primary key contains no
duplicates. However, if we allow null values for a primary key then there can be multiple
tuples for which primary key is having null values. This would imply that we are allowing
duplicate values (NULL) for a primary key which itself violates the definition of primary key.
• Referential Integrity Constraint: This constraint is specified between two relations.
Foreign key in a relation R1 is the set of attributes in R1 that refer to primary key in another
relation R2 if the domain of foreign key attributes is same as that of primary key attributes
and the value of foreign key either occurs as a value of primary key in some tuple of R2 or
is NULL.
R1 is called the referencing relation and R2 is called referenced relation, and a referential
integrity constraint holds from R1 to R2. The main purpose of this constraint is to check that
data entered in one relation is consistent with the data entered in another relation. For
example, consider two relation schemas:
Dept_ID- the primary key of relation in Department, is also present in relation Teacher. The reason
is that every teacher belongs to a particular department. That means Dept_ID of Teacher relation
must have a value that exists in Dept_ID attribute of Department relation or it can be NULL in case
a teacher has not yet been assigned to a department. We say that Dept_ID of Teacher relation is a
foreign key that references primary key of Department relation (Dept_ID).
It is not necessary to have same name for foreign key as of the corresponding referenced primary
key.
The Primary key of this relation is RID (Resident ID). In order to store information about neighbor
we have created a foreign key Neighbor_RID that references RID of Residents. Note that the
referencing and referenced relation are same in this case.
Structured Query Language (SQL)SQL is a language that is used to manage data stored in a
RDBMS. It comprises of a Data Definition Language (DDL) and a Data Manipulation Language
(DML) where DDL is a language which is used to define structure and constraints of data and DML
is used to insert, modify and delete data in a database.
SQL commands are used to perform all the operations. SQL uses the terms table, row and column
for the relational model terms relation, tuple and attribute.