Beruflich Dokumente
Kultur Dokumente
A candidate key is one that can identify each row of a table uniquely.
Generally a candidate key becomes the primary key of the table. If the table has
more than one candidate key, one of them will become the primary key, and the r
est are called alternate keys.
A key formed by combining at least two or more columns is called composite key.
Q9. What is a database index?
A database index is a data structure that improves the speed of data retrieval o
perations on a database table at the cost of slower writes and increased storage
space.
Indexes can be created using one or more columns of a database table, providing
the basis for both rapid random look ups and efficient access of ordered records
.
The disk space required to store the index is typically less than that required
by the table (since indexes usually contain only the key-fields according to whi
ch the table is to be arranged, and exclude all the other details in the table),
yielding the possibility to store indexes in memory for a table whose data is t
oo large to store in memory.
In a relational database, an index is a copy of one part of a table. Some databa
ses extend the power of indexing by allowing indexes to be created on functions
or expressions.
Indexes may be defined as unique or non-unique. A unique index acts as a constra
int on the table by preventing duplicate entries in the index and thus the backi
ng table.
Q10. Explain different types of index architectures?
Index architecture generally classified into Clustered indexes and Non-Clustered
indexes.
Clustered Index: In a clustered index, all the rows in the table are stored in t
he order of the clustered index key. So, there can be only one clustered index p
er table. Basically the data is re-ordered and stored everytime when new records
are added.
Non-clustered Index: The non-clustered index tree contains the index keys in sor
ted order, with the leaf level of the index containing the pointer to the page a
nd the row number in the data page. Typically created on column used in JOIN, WH
ERE, and ORDER BY clauses.
Q1. What are constraints? Give some examples.
Constraints enable the RDBMS enforce the integrity of the database automatically
, without needing you to create triggers, rule or defaults.
Types of constraints: NOT NULL, CHECK, UNIQUE, PRIMARY KEY, FOREIGN KEY.
Q2. Give two examples of referential integrity constraints.
A primary key and a foreign key.
Q3. What is a join and explain different types of joins.
Joins are used in queries to explain how different tables are related. Joins als
o let you select data from a table depending upon data from another table.
Types of joins: INNER JOINs, OUTER JOINs, CROSS JOINs. OUTER JOINs are further c
lassified as LEFT OUTER JOINS, RIGHT OUTER JOINS and FULL OUTER JOINS.
Q4. What is a self join?
Self join is just like any other join, except that two instances of the same tab
le will be joined in the query.
Q5. What is a Cartesian product? What causes it?
A Cartesian product is the result of an unrestricted join of two or more tables.
The result set of a three table Cartesian product will have x * y * z number of
rows where x, y, z correspond to the number of rows in each table involved in t
he join. It is caused by specifying a table in the FROM clause without joining i
t to another table.
Q6. What is the difference of a LEFT JOIN and an INNER JOIN statement?
A LEFT JOIN will take ALL the values from the first declared table and matching
values from the second declared table based on the column the join has been decl
ared on.
An INNER JOIN will take only matching values from both tables.