0% found this document useful (0 votes)
65 views6 pages

SPL2 SQL-like Syntax Explained

The document is a comprehensive question bank covering various topics related to Relational Database Management Systems (RDBMS). It includes sections on data models, ER to relational mapping, database structure, SQL commands, normalization, and practical SQL queries. Additionally, it features multiple-choice questions to test knowledge on key concepts in database design and management.

Uploaded by

sachyaxyz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views6 pages

SPL2 SQL-like Syntax Explained

The document is a comprehensive question bank covering various topics related to Relational Database Management Systems (RDBMS). It includes sections on data models, ER to relational mapping, database structure, SQL commands, normalization, and practical SQL queries. Additionally, it features multiple-choice questions to test knowledge on key concepts in database design and management.

Uploaded by

sachyaxyz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

QUESTION BANK

2. Relational Database Management System


1. Data Models & Types

 Q1: What is a data model? Explain its importance in database systems.


 Q2: Discuss the types of data models used in DBMS. Give an example of each.
 Q3: Differentiate between a conceptual, logical, and physical data model.
 Q4: Explain the relational data model with an example.
 Q5: What are the key differences between the hierarchical and network data models?

2. ER to Relational Mapping

 Q6: What is the Entity-Relationship (ER) model? Explain its components.


 Q7: How is an ER diagram converted into a relational schema? Provide an example.
 Q8: Describe the process of mapping the following ER components into a relational
schema:
o Entity Set
o Relationship Set
o Attributes
 Q9: What are the challenges faced when converting ER diagrams into relational
databases?
 Q10: Explain how a weak entity and its relationship are mapped in the relational model.

3. Structure of Relational Databases

 Q11: Define a relational database. What are the components of a relational database
structure?
 Q12: What is a table in a relational database? How does it relate to rows, columns, and
primary keys?
 Q13: Explain the concept of foreign keys in relational databases with an example.
 Q14: Discuss the differences between schema and instance in the context of a relational
database.
 Q15: What is a relational schema? Provide an example to illustrate.

4. Creation and Manipulation of Databases using Basic SQL (DDL, DML, DCL, TCL)

 Q16: Explain the differences between DDL, DML, DCL, and TCL with examples.
 Q17: What is the purpose of the CREATE statement in SQL? Provide a syntax example.
 Q18: Describe the INSERT INTO statement in SQL and give an example.
 Q19: What is the function of the UPDATE statement in SQL? Illustrate with an
example.
 Q20: Explain DROP, ALTER, and TRUNCATE commands in SQL. How do they
differ?
 Q21: What is SELECT statement in SQL? Provide an example query.
 Q22: Write an SQL query to retrieve all employees who earn more than $50,000 from the
employee table.
 Q23: What does COMMIT and ROLLBACK mean in SQL? How are they used in
transaction control?
 Q24: Describe the GRANT and REVOKE commands in SQL. When would they be
used?
 Q25: Write a SQL query to delete all records from a table.

5. Normalization

 Q26: What is normalization? Why is it important in database design?


 Q27: Describe the different types of anomalies (update, insertion, deletion) in a non-
normalized database.
 Q28: What are the various normal forms? Explain each with examples.
 Q29: Define functional dependency. Give an example and explain its role in
normalization.
 Q30: What are the steps involved in normalizing a database to 1NF, 2NF, and 3NF?

6. Normal Forms - 1NF, 2NF, 3NF, BCNF

 Q31: Define 1NF (First Normal Form). Provide an example of a non-1NF and how to
convert it to 1NF.
 Q32: What is 2NF (Second Normal Form)? Explain the concept of partial dependency
with an example.
 Q33: Explain 3NF (Third Normal Form). What is a transitive dependency? Give an
example.
 Q34: What is Boyce-Codd Normal Form (BCNF)? How does it differ from 3NF?
 Q35: Given a relation, convert it into 1NF, 2NF, and 3NF.
SQL Query Practical Questions

1. Database Creation and Table Management

 Q1: Create a database named University.


 Q2: Create the following table in the University database:
o Student (StudentID, FirstName, LastName, Age, DepartmentID)
o Department (DepartmentID, DepartmentName)
 Q3: Add a new column Email of type VARCHAR(100) to the Student table.
 Q4: Delete the Department table from the database University.
 Q5: Rename the FirstName column in the Student table to StudentFirstName.

2. Inserting, Updating, and Deleting Data

 Q6: Insert the following records into the Student table:


o (1, 'John', 'Doe', 20, 101)
o (2, 'Jane', 'Smith', 22, 102)
o (3, 'Alice', 'Johnson', 21, 103)
 Q7: Update the age of the student with StudentID = 2 to 23 in the Student table.
 Q8: Delete the student with StudentID = 1 from the Student table.

3. Querying Data

 Q9: Write an SQL query to select all the columns from the Student table where the student's
age is greater than 21.
 Q10: Write an SQL query to select only the FirstName and LastName of students from the
Student table who belong to department DepartmentID = 102.
 Q11: List the departments (DepartmentName) along with the number of students in each
department. You should use an INNER JOIN between Student and Department tables.

4. Aggregate Functions and Grouping

 Q12: Write a query to calculate the average age of students in the Student table.
 Q13: Find the total number of students in each department using a GROUP BY clause. Show the
department name and the student count.
 Q14: Write a query to find the maximum and minimum age of students in the Student table.
5. SQL Joins

 Q15: Write an SQL query to list the StudentFirstName, StudentLastName, and


DepartmentName for all students, using an INNER JOIN between Student and Department
tables.
 Q16: Write an SQL query to list all students along with their department name, even if a student
does not belong to any department (Use LEFT JOIN).
 Q17: Write an SQL query to find all departments that have no students enrolled (Use RIGHT
JOIN or LEFT JOIN).

Multiple Choice Questions (MCQs)

1. What is the main goal of normalization in a database?

a) To minimize data redundancy


b) To increase data redundancy
c) To decrease query performance
d) To maintain database integrity

Answer: a) To minimize data redundancy

2. Which of the following is a feature of 1NF?

a) No repeating groups of data


b) No partial dependency
c) No transitive dependency
d) No multivalued attributes

Answer: a) No repeating groups of data

3. Which of the following SQL commands is used to define the structure of a database?

a) DDL
b) DML
c) TCL
d) DCL

Answer: a) DDL

4. In the relational model, a primary key:

a) Can have duplicate values


b) Can be null
c) Uniquely identifies each record in a table
d) Has no relation to other keys

Answer: c) Uniquely identifies each record in a table

5. Which of the following is true about 2NF?

a) A table is in 2NF if it is in 1NF and has no transitive dependencies


b) A table is in 2NF if it is in 1NF and has no partial dependencies
c) A table is in 2NF if it contains no repeating groups
d) A table is in 2NF if it is free from all anomalies

Answer: b) A table is in 2NF if it is in 1NF and has no partial dependencies

6. Which of the following is an example of a functional dependency?

a) StudentID → StudentName
b) StudentName → StudentID
c) StudentID → CourseID
d) Both a and b

Answer: a) StudentID → StudentName

7. What is the purpose of the GRANT statement in SQL?

a) To revoke a user’s privileges


b) To add a new user
c) To assign privileges to a user
d) To change the database schema

Answer: c) To assign privileges to a user

8. Which of the following is true about BCNF?

a) BCNF is a stricter version of 3NF


b) BCNF does not deal with transitive dependencies
c) BCNF allows partial dependencies
d) BCNF is the same as 3NF

Answer: a) BCNF is a stricter version of 3NF

9. The process of removing transitive dependency is achieved by which normalization form?

a) 1NF
b) 2NF
c) 3NF
d) BCNF

Answer: c) 3NF

10. In SQL, which command is used to update data in an existing table?

a) SELECT
b) INSERT
c) UPDATE
d) DELETE

Answer: c) UPDATE

Common questions

Powered by AI

The SQL INNER JOIN statement is highly advantageous for managing relational databases as it allows for the selective combination of rows from two or more tables based on a related column between them . This join ensures that only records with matching values in the connected columns are returned in the result set, thus efficiently reducing data to only relevant information and maintaining a clear relational perspective . INNER JOINs facilitate complex queries, supporting thorough data analysis and reporting by effectively linking disparate datasets and ensuring data accuracy without redundancy .

The GRANT command in SQL assigns specific privileges to users or roles for accessing database objects like tables, views, and procedures. This command is integral to implementing controlled access, permitting users to execute tasks such as SELECT, INSERT, or DELETE, enhancing security management by ensuring users have appropriate access levels . Conversely, REVOKE removes privileges previously granted, preventing users from accessing or altering data sources, crucial for maintaining data integrity and security when roles change or when minimizing potential vulnerabilities . These commands play a pivotal role in enforcing database security policies, adhering to the principle of least privilege .

A partial dependency in a database arises when a non-prime attribute is functionally dependent on a part of a composite primary key, rather than the whole key. For a table to achieve 2NF (Second Normal Form), it must first be in 1NF, and all partial dependencies must be removed . This means every non-prime attribute should depend on the entire primary key. By eliminating partial dependencies, 2NF reduces redundancy and ensures that attributes are stored only once, helping maintain the integrity and efficiency of the database .

Normalization aims to minimize data redundancy by organizing data into tables in a way that reduces duplicate data. This process enhances database efficiency and integrity by formalizing how data is stored and related . By removing redundancy, normalization helps prevent update anomalies, where changes to data are inconsistent across redundant records. It also helps in maintaining database integrity by enforcing rules that ensure data dependencies are logically stored, thus reducing the chances of anomalous data . Ultimately, normalization leads to clearer data relationships and maintains consistency through the use of foreign keys and constraints .

Boyce-Codd Normal Form (BCNF) extends the principles of 3NF by addressing situations where a table is in 3NF but still has anomalies due to dependencies among candidate keys. While 3NF handles transitive dependencies, BCNF requires that no functional dependency exists in a table where a non-super key attribute is functionally dependent on any functionally dependent subset . BCNF is preferred in database design when eliminating all forms of redundancy for data integrity is critical, particularly where the data model contains complex relationships that could lead to anomalies not resolved in 3NF, ensuring that every determinant is a candidate key .

Foreign keys are critical in ensuring referential integrity within relational databases by creating dependencies between tables through a common field. By doing so, they enforce logical relationships and constraints that prevent database anomalies caused by orphan records or mismatched data entries . For example, a foreign key in a 'Order' table referencing a 'Customer' table ensures that every order has a corresponding valid customer, thereby maintaining consistency across tables . Foreign keys help maintain coherence in relational data, supporting complex queries and operations while preserving data integrity and aiding in normalization .

To convert an ER diagram into a relational schema, follow these steps: 1) Convert each entity set into a table, where the table includes all the attributes of the entity set . For example, for an entity 'Student', create a table 'Student' with attributes like 'StudentID' and 'Name'. 2) For each relationship set, create a new table that includes the primary keys of the related entity sets as foreign keys . For instance, for a many-to-many relationship 'Enrolment' between 'Student' and 'Course', create a table 'Enrolment' that includes 'StudentID' and 'CourseID' . 3) Add attributes from the relationship (if any) to the new table or to the table of the entity to which the relationship is connected .

The SQL DROP command permanently removes a table, its structure, and data from a database, effectively erasing it without the possibility of recovery . The ALTER command modifies an existing database object's structure, such as adding or deleting a column in a table, without affecting the existing data unless specified . The TRUNCATE command resembles DELETE but is faster and uses less transaction log space because it removes all rows from a table but retains the table structure for future use . Each command varies in its impact, with DROP affecting the schema and data, ALTER affecting only the schema, and TRUNCATE affecting only the data .

The relational data model organizes data in tables (relations) with rows and columns, using primary keys to uniquely identify each row. It allows for easy querying and data manipulation through structured query language (SQL). In contrast, the hierarchical data model organizes data in a tree-like structure, where each record has a single parent, which can make it challenging to handle relationships that don't fit a strict hierarchy . The network model allows more complex relationships by using a graph structure, enabling each record to have multiple parent and child records, but this complexity can make such models harder to design and maintain .

Converting ER diagrams into relational databases can pose several challenges: First, handling many-to-many relationships requires creating additional tables to capture the association, potentially increasing complexity . Second, mapping weak entities correctly, which depend on strong entities, requires ensuring that foreign keys are used properly to maintain referential integrity . Another challenge is ensuring that unique constraints and keys align with the business rules intended by the ER model . Furthermore, accurately translating complex attribute types or composite attributes into a flat table structure can be difficult .

You might also like