Water Industry Process Automation & Control Monthly - April 2024
DBMS
1. what is the primary key super key
foreign key and candidate key in the
dbms
super key :]
A Super key is any combination of fields within a table that uniquely identifies each
record within that table.
2. Candidate Key
A candidate is a subset of a super key. A candidate key is a single field or the least combination
of fields that uniquely identifies each record in the table. The least combination of fields
distinguishes a candidate key from a super key. Every table must have at least one candidate key
but at the same time can have several.
3. • As an example we might have a student_id that uniquely identifies the students in a student
table. This would be a candidate key. But in the same table we might have the student’s first
name and last name that also, when combined, uniquely identify the student in a student
table. These would both be candidate keys.
In order to be eligible for a candidate key it must pass certain criteria.
• It must contain unique values
• It must not contain null values
• It contains the minimum number of fields to ensure uniqueness
• It must uniquely identify each record in the table
• Once your candidate keys have been identified you can now select one to be your primary
key
4. primary key
A primary key is a candidate key that is most appropriate to be the main reference key for the
table. As its name suggests, it is the primary key of reference for the table and is used
throughout the database to help establish relationships with other tables. As with any
candidate key the primary key must contain unique values, must never be null and uniquely
identify each record in the table.
As an example, a student id might be a primary key in a student table, a department code in a
table of all departments in an organisation. This module has the code DH3D 35 that is no doubt
used in a database somewhere to identify RDBMS as a unit in a table of modules. In the table
below we have selected the candidate key student_id to be our most appropriate primary key
Primary keys are mandatory for every table each record must have a value for its primary key.
When choosing a primary key from the pool of candidate keys always choose a single simple
key over a composite key.
5. • Foreign Key
A foreign key is generally a primary key from one table that appears as a field in another where
the first table has a relationship to the second. In other words, if we had a table A with a
primary key X that linked to a table B where X was a field in B, then X would be a foreign key in
B.
An example might be a student table that contains the course_id the student is attending.
Another table lists the courses on offer with course_id being the primary key. The 2 tables are
linked through course_id and as such course_id would be a foreign key in the student table.
6. Query processor :A query processor is one of the major components of a
relational database or an electronic database in which data is stored in tables of rows and
columns. It complements the storage engine, which writes and reads data to and from storage
media.
7. FULL OUTER JOIN Keyword
The FULL OUTER JOIN keyword returns all rows from the left table (table1) and from the right
table (table2).
The FULL OUTER JOIN keyword combines the result of both LEFT and RIGHT joins.
SQL FULL OUTER JOIN Syntax:
SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name=table2.column_name;
8. Inner join:
The most frequently used and important of the joins is the INNER JOIN. They are also referred to
as an EQUIJOIN.
The INNER JOIN creates a new result table by combining column values of two tables (table1
and table2) based upon the join-predicate. The query compares each row of table1 with each
row of table2 to find all pairs of rows which satisfy the join-predicate. When the join-predicate is
satisfied, column values for each matched pair of rows of A and B are combined into a result
row.
• Syntax:
The basic syntax of INNER JOIN is as follows:
SELECT table1.column1, table2.column2...
FROM table1
INNER JOIN table2
ON table1.common_field = table2.common_field;
9. What are five main functions of a database administrator?
Five main functions of a database administrator are:
• To create the scheme definition
• To define the storage structure and access
methods
• To modify the scheme and/or physical
organization when necessary
• To grant authorization for data access
• To specify integrity constraints
10. The major functions of these various phases are summarized
as follows:
1. Database planning. Support overall organizational business plan. Develop a data
administration plan and design the database environment.
2. Database analysis. Identifying data entities used by the organization, relationships, and
documenting them (ER diagram). Define business rules and operational requirements.
3. Database design. Includes logical and physical design. Convert ER diagram to relational
tables. Design integrity controls.
4. Database implementation. First step is creation and initial load of the database - called
populating the database. Resolve data inconsistencies. Establish security controls. Establish
backup and recovery procedures. Train system users.
5. Operation and maintenance. Update database to keep it current - done by application
programs. Must include auditing the database for tuning and reorganization.
6. Growth and change. Modify the database to reflect changes in the organization. Monitor
database performance for efficiency and customer satisfaction.
12. Generalization
Generalization is a bottom-up approach in which two lower level entities combine to form a
higher level entity. In generalization, the higher level entity can also combine with other lower
level entity to make further higher level entity.
13. Specialization
Specialization is opposite to Generalization. It is a top-down approach in which one higher level
entity can be broken down into two lower level entity. In specialization, some higher level
entities may not have lower-level entity sets at all.
14. • Aggregration
Aggregration is a process when relation between two entity is treated as a single entity. Here
the relation between Center and Course, is acting as an Entity in relation with Visitor.
15. Primary index:
• It is an ordered file whose records are of fixed length
with two fields.
• Only based on the primary key.
• The total number of entries in the index is the same as
the number of disk blocks in the ordered data file.
• Primary index is a king of nondense (sparse) index.
• There may be at most one primary index for a file
• Needs less storage space.
Difference between primary and secondary
index in dbms
16. Secondary index
• It provides a secondary means of accessing a file
for which some primary access already exists.
• May be based on candidate key or secondary key.
• It has a large number entries due to duplication.
• Secondary index is a kind of dense index.
• There may be more than one secondary indexes
for the same file.
• Needs more storage space and longer search
time.
17. Definition - What does Hashing mean
• Hashing is also a method of sorting key values in a database
table in an efficient manner.
• Hashing is one way to enable security during the process of
message transmission when the message is intended for a
particular recipient only. A formula generates the hash, which
helps to protect the security of the transmission from
unauthorized users.
• Hashing is generating a value or values from a string of text using
a mathematical function
18. Triggers - a trigger is a piece of SQL to execute either before or after an update, insert, or
delete in a database. An example of a trigger in plain English might be something like: before
updating a customer record, save a copy of the current record. Which would look something
like:
CREATE TRIGGER triggerName
AFTER UPDATE
INSERT INTO CustomerLog (blah, blah, blah)
SELECT blah, blah, blah FROM deleted
Assertions - An assertion is a piece of SQL which makes sure a condition is satisfied or it
stops action being taken on a database object. It could mean locking out the whole table or
even the whole database.