RDBMS 12 Question Answer
RDBMS 12 Question Answer
Summary
File system suffers from Data Redundancy, Data Inconsistency, Data Isolation, Data
Database Management System (DBMS) is a software to create and manage databases. A database is a
collection of tables.
A database constraint is a restriction on the type of data that that can be inserted into the table.
Database schema and database constraints are stored in database Catalog. Whereas the snapshot of
the database at any given time is the database instance.
Relational DBMS (RDBMS) is used to store data in related tables. Rows and columns of a
table are called tuples and attributed respectively. A table is referred to as a relation.
Restrictions on data stored in a RDBMS is applied by use of keys such as Candidate Key,Primary Key,
Composite Primary Key, Foreign Key.
Each column in a table represents a feature (attribute) of a record. Table stores the information for an
entity whereas a row represents a record.
Each row in a table represents a record. A tuple is a collection of attribute values that makes a record
unique.
A tuple is a unique entity whereas attribute values can be duplicate in the table.
A. Multiple choice questions
collection of data or information that can be accessed, updated, and managed (d)
2. Which of the following is not a valid SQL type? (a) float (c) numeric (c) decimal (d) character
3. In DBMS, table is known as _________ and row is known as __________. (a) relation, tuple
4. In any table, the data types describe the kind of _________ that it can contain. (a) table (b)
5. The SQL statement used to select data items from the database is (a) SELECT (b) USE (c)
6. The database can be renamed using __________ SQL statement (a) CREATE DATABASE (b)
7. The syntax used to show all databases is (a) USE DATABASES (b) SELECT DATABASES (c)
8. In a database table the field which uniquely identifies each row in the table is known as
______ (a) primary key (b) unique key (c) composite key (d) foreign key
9. Foreign key is a _______ key in another table. (a) primary (b) unique (c) composite (d)
candidate key
10. The multiple columns that are used as primary key is known as (a) unique key (b)
11. Which of the following key is used to link between two tables (a) primary (b) foreign (c) composite
(d) unique
12. A primary key cannot be (a) Zero (b) foreign key (c) duplicate (d) NULL
known as __________ .
5. Data Definition language is the language which is used to defining the ______of relation.
5. To make a link between two tables, We can use foreign key constraints.
Answer:A file system is a way of organizing and storing files on a computer or storage device. It
provides
a structure for naming, storing, and retrieving files.
Note: These limitations have led to the development of alternative data storage and
management
systems, such as databases and content management systems.
2. Why foreign keys are allowed to have NULL values? Explain with an example.
Answer: Foreign keys are allowed to have NULL values because they might not always have a
matching
value in the referenced table.
Example:
*Orders*
*Customers*
In this example, the "CustomerID" field in the Orders table is a foreign key that references the
"CustomerID" in the Customers table. However, if an order is placed by a customer who hasn't
created
an account (a "guest" customer), there won't be a matching CustomerID in the Customers table.
In this
case, the CustomerID field in the Orders table would be NULL, indicating that there is no
associated
customer.
Allowing NULL values in foreign keys provides flexibility in handling such scenarios, where the
relationship between tables might not always exist.
3. What are the limitations of file system and how that are overcome by DBMS?
Answer: Limitations of File System:
1. *Data Redundancy and Duplication*: DBMS stores data in a single place, reducing duplication
and
ensuring data consistency.
2. *Data Inconsistency*: DBMS enforces data integrity constraints, ensuring data accuracy and
consistency.
3. *Data Search and Retrieval*: DBMS provides efficient search and retrieval mechanisms,
making data
access faster.
4. *Data Security and Integrity*: DBMS offers robust security features, access control, and
transaction
logging to ensure data integrity and security.
5. *Data Isolation and Scalability*: DBMS allows concurrent access, supports large data
volumes, and scales horizontally, ensuring data availability and performance.
By overcoming these limitations, DBMS provides a more efficient, secure, and scalable way to
manage
data compared to traditional file systems.
1. Tables or relations: Define the structure of data storage, including columns (fields) and data
types.
2. Relationships: Define how tables are connected, such as one-to-one, one-to-many, or many-to
-.many
relationships.
3. Indexes: Define how data is indexed for efficient retrieval.
4. Views: Define virtual tables based on queries.
5. Constraints: Define rules for data integrity, such as primary keys, foreign keys, and check
constraints.
6. Stored procedures: Define reusable code blocks for performing specific tasks.
- Duplicate records
- Multiple copies of the same data in different tables or files
- Unnormalized data structures
To avoid these problems, data normalization techniques are used to eliminate data redundancy
and
ensure data consistency and efficiency.
6. How data redundancy problem is solved in DBMS?
Answer:In DBMS, data redundancy is solved through:
1. *Data Normalization*: Organizing data into tables and removing duplicates by splitting large
tables
into smaller ones.
2. *First Normal Form (1NF)*: Ensuring each table cell contains a single value.
3. *Second Normal Form (2NF)*: Moving redundant data to a separate table.
4. *Third Normal Form (3NF)*: Removing data that depends on another field's value.
- Database state: Refers to the actual data stored in the database at a given point in time. It's the
current
set of values in the database.
- Database schema: Refers to the structure or organization of the database, including table
definitions,
relationships, and constraints. It's the blueprint or design of the database.
(b) Primary key vs Foreign key:
- Primary key (PK): A unique identifier for a record in a table, ensuring data consistency and
uniqueness.
It's a column or set of columns that uniquely identifies each row.
- Foreign key (FK): A field in a table that references the primary key of another table, establishing a
relationship between tables.
(c) Degree and cardinality of a relation:
- Degree: The number of attributes or columns in a relation (table).
- Cardinality: The number of tuples or rows in a relation (table).
Example:
- A relation (table) with 5 columns (attributes) has a degree of 5.
- A relation (table) with 10 rows (tuples) has a cardinality of 10.
In summary:
- Database state is the data, while schema is the structure.
- Primary key identifies a record, while foreign key links records between tables.
- Degree is the number of columns, and cardinality is the number of rows in a table.
10. Explain the terms (a) Relation (b) Domain (c) Tuple (d) Attribute (e) Degree (f) Cardinality (g)
Primary
Key (h) Foreign Key
Answer: Here are the explanations:
(a) Relation: A relation is a table in a database that contains a set of related data. It's a
fundamental
concept in relational databases.
(b) Domain: A domain is the set of possible values that an attribute can take. It defines the
range of
values for a specific attribute.
(c) Tuple: A tuple is a single row or record in a relation (table). It's a collection of values that
represent a
single entity or instance.
(d) Attribute: An attribute is a column or field in a relation (table). It defines a specific
characteristic or
feature of the data.
(e) Degree: The degree of a relation is the number of attributes (columns) it contains.
(f) Cardinality: The cardinality of a relation is the number of tuples (rows) it contains.
(g) Primary Key (PK): A primary key is a unique identifier for a tuple (row) in a relation. It's a
single
attribute or a set of attributes that uniquely identifies each tuple.
(h) Foreign Key (FK): A foreign key is an attribute in a relation that references the primary key of
another
relation. It establishes a relationship between two relations.
Example:
Consider a relation "Students" with attributes:
- Student_ID (Primary Key)
- Name
- Age
- Major
- Relation: Students
- Domain: The set of possible values for Age (e.g., 18-25)
- Tuple: A single row representing a student (e.g., John, 20, Computer Science)
- Attribute: Student_ID, Name, Age, Major
- Degree: 4 (four attributes)
- Cardinality: The number of students ( tuples) in the relation
- Primary Key: Student_ID
- Foreign Key: If another relation "Courses" has an attribute "Student_ID" that references the
Students
relation, it's a Foreign Key.
11. Describe the various integrity constraints?
Answer:Integrity constraints are rules that ensure the accuracy, consistency, and reliability of
data in a
database. The following are various types of integrity constraints:
1. *Entity Integrity*: Ensures that each row in a table has a unique primary key value.
2. *Referential Integrity*: Ensures that a foreign key value matches a primary key value in
another table.
3. *Domain Integrity*: Ensures that data values conform to the defined domain (e.g., format,
range, or
set of values).
4. *Unique Constraint*: Ensures that all values in a column or set of columns are unique.
5. *Check Constraint*: Ensures that data values meet specific conditions or rules (e.g., age > 18).
6. *Not Null Constraint*: Ensures that a column cannot contain null values.
7. *Default Constraint*: Provides a default value for a column when no value is specified.
8. *Primary Key Constraint*: Ensures that a primary key value is unique and not null.
These integrity constraints help maintain data consistency, prevent errors, and ensure that data is
reliable and trustworthy.
SQL is a open source, interactive, portable, faster query processing, standardized and
SQL is divided into five types like DDL, DML, DQL, TCL and DCL.
DDL (Data Definition Language) includes SQL statements such as, Create table, Alter table
Create command is used to create database and its further objects like Table, View.
DML (Data Manipulation Language) includes SQL statements such as, insert, select,
A table is a collection of rows and columns, where each row is a record and columns
DESCRIBE TABLE statement is used to view the structure of an already existing table
ALTER TABLE statement is used to make changes in the structure of a table like adding,
removing column and changing datatype of column(s). It is also used to apply/remove any
DROP statement is used to remove a database or a table permanently from the database
system.
TRUNCATE statement is used to delete all records from the table but table structure will
exist in database.
INSERT INTO statement is used to insert new records in any existing table
CREATE TABLE statement can also be used to create new table from existing tables/s.
RENAME statement is used to change the name of existing tables of other database
objects.
Views in any database is a special kind of virtual table that is created from one or more
DISTINCT clause is used to eliminate repetition and display the values only once.
The BETWEEN operator defines the range of values inclusive of boundary values.
The IN operator selects values that match any value in the given list of values.
ORDER BY clause is used to display the result of a SQL query in ascending or descending
order with respect to specified attribute values. By default, the order is ascending.
LIKE operator is used for pattern matching. % and _ are two wild card characters. The per
cent (%) symbol is used to represent zero or more characters. The underscore (_) symbol is
1.Which of the following is not a valid aggregate function? (a) COUNT (b) COMPUTE (c) SUM
(d) MAX
2.DDL stands for (a) Data Describe Language (b) Definition Data Language (c) Data
3.Which of the following SQL command is used to remove data from table (a) Collapse (b)
4.The records and structure of a table may be removed or deleted from the database using
which command? (a) Remove (b) Delete (c) Drop (d) Truncate
5.SQL ___ statement can be used to delete or drop existing databases in a SQL schema. (a)
Create Database (b) Rename Database (c) Drop Database (d) Select Database
6.Using DROP TABLE command in SQL (a) Drop the table structure (b) Drop the Integrity
7.Using DROP TABLE command in SQL (a) Drop the table structure (b) Drop the Integrity
constraints (c) Drop the Relationship (d) Noe of the above
8.TRUNCATE TABLE requires (a) Where Clause (b) Having Clause (c) Both A And B (d) None
of the above
9.Which of the following clause is used to add a Primary Key constraint after creating table
10. Which of the following clause is used to remove a primary key constraint (a) Delete (b)
11. Which of the following SQL statement is used to give result in sorted order (a) Sort By (b)
12. Commands under DCL are (a) GRANT (b) REVOKE (c) Both A. and B. (d) None of the above
13. The SQL command to retrieve table records is (a) RETRIEVE (b) SELECT (c) CREATE (d)
ALTER
14. Which of the following operator is used for pattern matching in SQL? (a) BETWEEN
operator (b) LIKE operator (c) EXISTS operator (d) None of these
15. Which operator is used to check the absence of data in any column (a) EXISTS operator (b)
16. Which of the following keyword is used to select only unique values from any column (a)
5. The _______ command is used to remove all records only from a table.
11. To sort the result of a query in descending order, we can use clause ______
12. To extract unique values from a column, user can use __________ clause.
3. DROP command is used to delete the structure of a table from the database.
6. Aggregate functions are used to perform calculations on multiple values and returns a
single value.
8. DML is used to create a new database objects like table and view.
10. The name of any tables once its created and records are inserted cannot be change.
Ans:Here is the CREATE statement to create the Book relation with the given constraints:
```
CREATE TABLE Book (
ISBN TEXT PRIMARY KEY,
Title TEXT NOT NULL,
Author TEXT NOT NULL,
PubID TEXT NOT NULL,
Price NUMERIC NOT NULL,
Pages NUMERIC NOT NULL
);
```
This CREATE statement defines the Book table with the specified columns and constraints:
- ISBN is the primary key, ensuring unique values.
- All other columns (Title, Author, PubID, Price, and Pages) are defined as NOT NULL, ensuring
that
values must be provided for these fields.
Note that the specific syntax may vary slightly depending on the database management system
(DBMS)
being used.
9. Modify the Book table in previous question and add one more new field Discount (Numeric).
Ans:Here is the ALTER TABLE statement to add the new field Discount (Numeric) to the existing
Book
table:
```
ALTER TABLE Book
ADD COLUMN Discount NUMERIC;
```
This will add the new column Discount to the Book table, with a numeric data type.
If you want to specify a default value for the Discount column or add a constraint (e.g., NOT
NULL), you
can modify the statement accordingly:
```
ALTER TABLE Book
ADD COLUMN Discount NUMERIC NOT NULL DEFAULT 0;
```
This will add the Discount column with a default value of 0 and ensure that a value must be
provided for
this field (NOT NULL).
Note that the specific syntax may vary slightly depending on the database management system
(DBMS)
being used.
10. Shyam has created one database name Mycontacts but he is not able to create new table in
this
database. What command should Shyam be used before creating the table?
Ans:Before creating a table in the Mycontacts database, Shyam needs to switch to that
database using
the USE command. The syntax is:
USE Mycontacts;
This command tells the database management system to switch to the Mycontacts database,
making it
the current database for subsequent commands.
After executing the USE command, Shyam can create a new table using the CREATE TABLE
command.
Example:
```
USE Mycontacts;
CREATE TABLE contacts (
id INT PRIMARY KEY,
name VARCHAR(50),
email VARCHAR(100)
);
```
This will create a new table named "contacts" in the Mycontacts database.
11. Mr. Sachin Agrawal created two tables with Course as Primary Key in Table1 and Foreign
key in
Table2 while inserting new row in second Table2 Mr Agrawal is not able to insert new value in
the
column City. What could be the possible reason for this?
Ans:The possible reason for this issue is that the Foreign Key constraint in Table2 is referencing
the
Course column in Table1, and the value being inserted into the City column in Table2 does not
have a
matching Course value in Table1.
Foreign Key constraints ensure data consistency by requiring that the value in the foreign key
column (in
this case, Course in Table2) matches a value in the primary key column (Course in Table1). If
the value
doesn't exist in Table1, the insert operation in Table2 will fail.
To resolve this, Mr. Agrawal can:
1. Insert the corresponding Course value in Table1 first.
2. Then, insert the new row in Table2, including the City value.
Alternatively, if the City column in Table2 is not dependent on the Foreign Key constraint, he can
consider removing the Foreign Key constraint from the City column in Table2.
Chapter 3. Functions In SQL
SUMMARY
Single Row functions work on a single row of the table and return a single value.
Multiple Row functions work on a set of records as a whole and return a single value.
GROUP BY function is used to group rows of a table that contain the same values in a
specified column.
Join is an operation which is used to combine rows from two or more tables based on one
1. Which of the following is not an example of single row function (a) MATH (b) STRING (c)
DATE (d) COUNT
2. Which of the following is not an example of multiple row function (a) MAX ( ) (b) MIN ( ) (c)
3. What is the functionality of SQL COUNT? (a) It returns the no of record of table (b) It
returns the no of record of database (c) It returns the no of record of row (d) It returns the
no of record of column
4. Date and Time functions accept date and time value as input and return output as (a)
numeric (b) string (c) Date and Time (d) Any of the above
5. String Functions accept character value as input and return output as (a) either character
or numeric values (b) string values (c) numeric values (d) character values
6. Which of the following is aggregate function in SQL (a) LEFT (b) AVG (c) JOIN (d) LEN
7. The SQL statement Select Round (47.956,-1) from Dual; (a) is illegal in SQL (b) prints a
8. Which of the following SQL operation cannot be performed on relations (a) Union, (b)
9. Which of the following is used to join two tables on equality condition on the common
attribute (a) JOIN with ON clause (b) NATURAL JOIN in FROM clause (c) Any of a or b (d)
NATURAL JOIN
10. What will be the Cartesian product of the two relations having 4 rows and 3 columns for
first relation and 3 rows and 4 columns in second relation. (a) degree 7 cardinality 12 (b)
1. Single row functions are applied on a single ______ and return a single value.
3. Math Functions accept numeric value as input and return a ______ value as a result.
4. MONTH (date) returns the month in ________ form from the date.
6. INSTR (string, substring) returns the position of the _________ of the substring in the given
string.)
7. MID (string, pos, n) returns a substring of size ___ starting from the specified position
8. LTRIM (string) returns the given string after removing ________ white space characters.
9. TRIM (string) returns the given string after removing both ________ and _________ white
space characters.
10. The _________ operation is used to get common tuples from two tables.
C. State True or False
4. INSTR (string, substring) returns 0, if the substring is not present in the string.
5. If n is not specified MID (string, pos, n), it returns the substring from the position 1 till end
of the string.
6. RTRIM (string) returns the given string after removing leading white space characters.
In summary:
- Single row functions process individual rows, returning a result for each row.
- Aggregate functions process groups of rows, returning a single result for the entire group.
Think of single row functions as processing individual items, while aggregate functions process
collections of items!
2. List the single row functions with example.
Ans:Here are some common single row functions with examples:
1. *Mathematical functions*
- ABS(-10) returns 10
- SQRT(16) returns 4
- ROUND(3.7) returns 4
- CEIL(3.2) returns 4
- FLOOR(3.8) returns 3
2. *String functions*
- UPPER('hello') returns 'HELLO'
- LOWER('WORLD') returns 'world'
- TRIM(' extra spaces ') returns 'extra spaces'
- LENGTH('hello') returns 5
- CONCAT('hello', 'world') returns 'helloworld'
3. *Date and Time functions*
- NOW() returns the current date and time
- DATE_FORMAT('2022-01-01', '%Y-%m-%d') returns '2022-01-01'
- DAYNAME('2022-01-01') returns 'Saturday'
- HOUR('12:30:00') returns 12
4. *Conversion functions*
- CAST('123' AS INTEGER) returns 123
- CONVERT('2022-01-01', DATE) returns '2022-01-01'
5. *Other functions*
- COALESCE(NULL, 'default') returns 'default'
- NULLIF('value', 'value') returns NULL
Note: These examples are for illustrative purposes and may vary depending on the specific
database
management system being used.
3. Differentiate between TRIM( ), LTRIM( ) and RTRIM( ) functions.
Ans:The TRIM(), LTRIM(), and RTRIM() functions are used to remove unwanted spaces from a
string, but
they differ in which sides of the string they operate on:
- TRIM(): Removes spaces from both the beginning (left) and end (right) of a string.
- Example: TRIM(' extra spaces ') returns 'extra spaces'
- LTRIM(): Removes spaces only from the beginning (left) of a string.
- Example: LTRIM(' extra spaces ') returns 'extra spaces '
- RTRIM(): Removes spaces only from the end (right) of a string.
- Example: RTRIM(' extra spaces ') returns ' extra spaces'
In summary:
- TRIM() removes spaces from both sides.
- LTRIM() removes spaces from the left side only.
- RTRIM() removes spaces from the right side only.
Think of it like trimming a garden:
- TRIM() is like trimming both edges of a hedge.
- LTRIM() is like trimming only the left edge.
- RTRIM() is like trimming only the right edge.
4. Demonstrate the use of LCASE( ) and UCASE( ) function with example.
Ans:The LCASE() and UCASE() functions are used in SQL to convert the case of a string. Here
are examples demonstrating their use:
Explanation:
LCASE('Hello World') converts the string 'Hello World' to all lowercase letters.
Explanation:
UCASE('Hello World') converts the string 'Hello World' to all uppercase letters.
In both cases, the functions LCASE() and UCASE() take a string input and return the string with all
characters converted to lowercase or uppercase, respectively. These functions are useful when you need
to standardize the case of string data for comparison or display purposes in SQL queries.
AVG():
- Returns the average value of a set of values.
- Example: AVG(salary) returns the average salary of all employees.
Let's consider a simple example to illustrate the difference:
Suppose we have a table with the following salaries:
| Salary |
| ------ |
| 1000 |
| 2000 |
| 3000 |
| 4000 |
| 5000 |
SUM(salary) would return: 1000 + 2000 + 3000 + 4000 + 5000 = 14000
AVG(salary) would return: 14000 / 5 = 2800
In this example:
- SUM(salary) gives you the total salary (14000).
- AVG(salary) gives you the average salary (2800).
So, SUM() adds up all the values, while AVG() calculates the average value by dividing the sum
by the
count of values.
8. A table Student has 4 rows and 2 column and another table has 3 rows and 4 columns. How
many
rows and columns will be there if we obtain the Cartesian product of these two tables?
Ans:If we obtain the Cartesian product (also known as the cross product or cross join) of the
two tables,
the resulting table will have:
- Rows: 4 (from the first table) x 3 (from the second table) = 12 rows
- Columns: 2 (from the first table) + 4 (from the second table) = 6 columns
So, the resulting table will have 12 rows and 6 columns.
In a Cartesian product, each row of the first table is paired with each row of the second table,
resulting
in a new table with the combined columns and a larger number of rows.
9. What will be the output of following SQL functions.
a)Select pow (3,2);
b) Select round (342.9234, 2);
c)Select length (‘Vocational Education’);
b) To display the specified number of characters from a particular position of the given string.
c) To display the name of the month in which you were born.
d) To display your name in capital letters.
Ans:Here are the SQL functions to perform the operations:
a) To display the day like "Monday", "Tuesday", from the date when India got independence
(August 15,
1947):
```
SELECT DAYNAME('1947-08-15') AS Independence_Day;
```
b) To display the specified number of characters from a particular position of the given string
(e.g., "
Vocational Education", starting from position 3, display 4 characters):
```
SELECT MID('Vocational Education', 3, 4) AS Substring;
```
c) To display the name of the month in which you were born (replace '1990-06-21' with your
birthdate):
```
SELECT MONTHNAME('1990-06-21') AS Birth_Month;
```
d) To display your name in capital letters (replace 'Your_Name' with your actual name):
```
SELECT UPPER('Your_Name') AS Name_In_Capitals;
```
Note: These functions are based on MySQL syntax. The exact syntax may vary depending on the
database management system being used.
,******************. .*****************.