You are on page 1of 6

OMC 301 – SECTION A

Q 1. A well-maintained relational DBMS has a high level of data integrity. What


features of a relational DBMS contribute towards this level of integrity?

Features of a relational DBMS contribute towards this level of integrity


(a) Data Integrity - Maintaining integrity of the data is an import process. If data loses
integrity, it becomes unusable and garbage. DBMS provides means to implement rules
to maintain integrity of the data. Once we specify which rules are to be implemented,
then DBMS can make sure that these rules are implemented always.

(b) Fault tolerance and recovery - DBMS provides great deal of fault tolerance. They
continue to run in spite of errors, if possible, allowing users to rectify the mistake in the
mean time. DBSM also allows recovery in the event of failure. For instance, if data on
the disk is completely lost due to disk failure then also data can be recovered to the
point of failure if proper back up of the data is available.

(c) Entity and Attribute - An entity is any object that is stored in the database. Each
entity is associated with a collection of attributes. For example, if you take a data of a
training institute, student is an entity as we store information about each student in the
database. Each student is associated with certain values such as roll number, name,
course etc., which are called as attributes of the entity. There will be relationship among
entities. The relationship between entities may be one-to-one, one-to-many or many-to-
many. If you take entities student, batch and subject, the following are the possible
relationships.
There is one-to-one relationship between batch and subject. One batch is associated
with only one subject. Three is one-to-many relationship between batch and student
entities. One batch may contain many students. There is many-to-many relationship
between student and subject entities. A single student may take many subjects and a
single subject may be taken by multiple students.

(d) Data Models - Data model is a way of storing and retrieving the data. There are
three different data models. Data models differ in the way they allow users to view and
manipulate relationships between entities. Each has its own way of storing the data.
The following are the three different data models:

(i) Hierarchical - In this model, data is stored in the form of a tree. The data is
represented by parent child relationship. Each tree contains a single root record and
one or more subordinate records. For example, each batch is root and students of the
batch will be subordinates. This model supports only one-to-many relationship between
entities. This was used in IBM’s Information management system, IMS.

(ii) Network - Data is stored along with pointers, which specify the relationship between
entities. This was used in Honeywell's Integrated Data Store, IDS. This model is
complex. It is difficult to understand both the way data is stored and the way data is
manipulated. It is capable of supporting many-to-many relationship between entities,
which hierarchical model doesn’t.

(iii) Relational - This stores data in the form of a table. Table is a collection of rows and
columns.
2. (a) Explain the various functions of RDBMS? Name the different categories of
RDBMS users and how they are different from each other.

(b)RDBMS has become most popular Database System worldwide? Justify your
answer with suitable example.

3. Differentiate among on any three of the following giving suitable examples:-

a) Primary Key

b) Candidate Key

c) Alternate Key

d) Unique Key

e) Super Key

4. Write SQL statements to create a table from existing table. What are the
advantages of creating a table from existing table?

Ans 4. SQL: CREATE TABLE From Existing Table

(a) Create Table - By Copying all columns from another table

Syntax
The syntax for the CREATE TABLE AS statement when copying all of the columns in
SQL is:
CREATE TABLE new_table
AS (SELECT * FROM old_table);

Example:
CREATE TABLE suppliers
AS (SELECT *
FROM companies
WHERE id > 1000);

This would create a new table called suppliers that included all columns from the
companies table. If there were records in the companies table, then the new suppliers
table would also contain the records selected by the SELECT statement.

(b) Create Table - By Copying selected columns from another table

Syntax
The syntax for the CREATE TABLE AS statement copying the selected columns is:

CREATE TABLE new_table


AS (SELECT column_1, column2, ... column_n
FROM old_table);

Example:

CREATE TABLE suppliers


AS (SELECT id, address, city, state, zip
FROM companies
WHERE id > 1000);

This would create a new table called suppliers, but the new table would only include the
specified columns from the companies table. Again, if there were records in the
companies table, then the new suppliers table would also contain the records selected
by the SELECT statement.

(c) Create Table - By Copying selected columns from multiple tables

Syntax

CREATE TABLE new_table


AS (SELECT column_1, column2, ... column_n
FROM old_table_1, old_table_2, ... old_table_n);

Example:

CREATE TABLE suppliers


AS (SELECT companies.id, companies.address, categories.cat_type
FROM companies, categories
WHERE companies.id = categories.id
AND companies.id > 1000);

This would create a new table called suppliers based on columns from both the
companies and categories tables.

(d) Create a from another table without copying any values from the old table.

Syntax

CREATE TABLE new_table


AS (SELECT *
FROM old_table WHERE 1=2);

Example:

CREATE TABLE suppliers


AS (SELECT *
FROM companies WHERE 1=2);

This would create a new table called suppliers that included all columns from the
companies table, but no data from the companies table.
Advantages of creating a table from existing table.

(a) We can import the properties of old table to the new table.

(b) Specific data from multiple old tables can be copied into the new table.

(c) Minimises the Database transaction time and records thus giving an optimum
performance from the database.

(d) Saves the time of user / administrator.

5. Explain the difference between the Drop & Delete, Commit & Rollback and Alter
& Update with suitable examples.

Ans 5. Consider the CUSTOMERS table having the following records −

+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 6 | Komal | 22 | MP | 4500.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
+----+----------+-----+-----------+----------+
SQL command can be divided into three subgroups, DDL, DML and DCL
DML – Data Manipulation Language
DCL – Data Control Language
TCL - Transaction Control Language

Differences between DELETE and DROP.

(a) DELETE remove some or all the tuples from a table. DROP can remove entire
schema, table, domain, or constraints from the database.

(b) DELETE is a Data Manipulation Language command. DROP is a Data Definition


Language command.

(c) WHERE clause can be used along with the DELETE command. No clause is used
along with DROP command.

(d) Actions performed by DELETE can be roll-backed. Actions performed by DROP


cannot be rollbacked.

(e) Even if we delete all the tuples of the table using DELETE, space occupied by the
table in the memory is not freed. Table deleted using DROP frees the table space from
memory.
(f) DELETE command is used to delete the rows inside a table and the DROP
command is used to delete the complete table itself.

In the following example DELETE would delete those records from the table which have
age = 25.

SQL> DELETE FROM EMPLOYEES


WHERE AGE = 25;

Thus, two rows from the table would be deleted

In the above example if we use DROP instead of DELETE then DROP will remove the
table from database.

SQL> DROP TABLE EMPLOYEES

Thus, the drop operation would remove the table and along with data.

Differences between Alter and Update.

(a) ALTER command is a Data Definition Language Command. UPDATE command is


a Data Manipulation Language Command.

(b) ALTER Command add, delete, modify the attributes of the relations (tables) in the
database. UPDATE Command modifies one or more records in the relations.

(c) Syntax for ALTER - ALTER TABLE table_name ADD column_name datatype;

(d) Syntax for UPDATE - UPDATE table_name SET column_name1 = value,


column_name2 = value, ...

(e) ALTER Command by default initializes values of all the tuple as NULL. UPDATE
Command sets specified values in the command to the tuples.

(f) ALTER Command operates on the attribute of a relation. Update Command


operates on the attribute value of a specific tuple in a relation.

In the above example if we use ADD a New Column to an existing table −

ALTER TABLE EMPLOYEES ADD SEX char(1);

Now, the EMPLOYEES table is changed and in SELECT statement we would see a
new column SEX.

The following query will update the ADDRESS for a customer whose ID number is 6 in
the table.
SQL> UPDATE EMPLOYEES
SET ADDRESS = 'Pune'
WHERE ID = 6;

Now, in the EMPLOYEES table ID=6 which had MP in address will be changed to
PUNE.

Differences between Commit & Rollback.

(a) COMMIT validates the modifications made by the current transaction. ROLLBACK
erases the modifications made by the current transaction.

(b) After execution of COMMIT statement, the transaction can not be ROLLBACK.

(c) Once ROLLBACK is executed database reaches its previous state, i.e. before the
execution of the first statement of the transaction.

(d) COMMIT occurs when the transaction gets executed successfully. ROLLBACK
occurs when the transaction is aborted in middle of the execution.

(e) Syntax for COMMIT - COMMIT;

(f) Syntax for ROLLBACK - ROLLBACK;

(g) To ensure, that the changes made by the transaction are permanently saved in the
database, use COMMIT after the transaction’s successful completion. In case the
transaction faces any error while execution then to undo the changes done by the
transaction, ROLLBACK is used.

In the following example DELETE would delete those records from the table which have
age = 25 and then COMMIT will save the changes in the database.

SQL> DELETE FROM EMPLOYEES


WHERE AGE = 25;
SQL> COMMIT;

Thus, two rows from the table would be deleted

In the above example if we use ROLLBACK instead of COMMIT then ROLLBACK will
undo the changes in the database.

SQL> DELETE FROM EMPLOYEES WHERE AGE = 25;


SQL> ROLLBACK;

Thus, the delete operation would not impact the table.

You might also like