Thursday

November 21st , 2024

FOLLOW US

SAMPLE QUESTIONS AND ANSWERS DATABASE 2024

featured img
Education

7 months ago




SAMPLE QUESTIONS AND ANSWERS DATABASE 2024

What is Normalization?


- Normalization: Process of organizing data in a database to reduce redundancy and improve data integrity.


State two 2 advantages of Normalization


- Data Integrity: Reduces data redundancy and inconsistencies, leading to improved accuracy and reliability.

- Efficient Database Design: Helps in optimizing storage space, simplifying data updates, and enhancing overall database performance.


State two 2 disadvantages of Normalization


- Increased Joins: Need for frequent joins between normalized tables can lead to performance issues, especially in complex queries.

- Complexity: Over-normalization can result in overly complex database schemas, making it challenging to query and maintain the database.


Explain with examples, the following terms

Polymorphism

Abstraction

Encapsulation

Inheritance 


### Polymorphism:

- Definition: Polymorphism allows objects of different classes to be treated as objects of a common superclass through method overriding.

- Example:

  ```python

  class Animal:

      def speak(self):

          pass

  

  class Dog(Animal):

      def speak(self):

          print("Woof!")

  

  class Cat(Animal):

      def speak(self):

          print("Meow!")

  

  def animal_speak(animal):

      animal.speak()

      

  dog = Dog()

  cat = Cat()

  

  animal_speak(dog)  # Output: Woof!

  animal_speak(cat)  # Output: Meow!

  ```


### Abstraction:

- Definition: Abstraction allows hiding the complex implementation details and showing only the necessary features to the user.

- Example:

  ```python

  from abc import ABC, abstractmethod

  

  class Shape(ABC):

      @abstractmethod

      def area(self):

          pass

  

  class Rectangle(Shape):

      def __init__(self, length, width):

          self.length = length

          self.width = width

  

      def area(self):

          return self.length * self.width

  

  rectangle = Rectangle(5, 3)

  print(rectangle.area())  # Output: 15

  ```


### Encapsulation:

- Definition: Encapsulation involves bundling data (attributes) and methods (behaviors) that operate on the data into a single unit (class) to restrict direct access to data.

- Example:

  ```python

  class Employee:

      def __init__(self, name, salary):

          self.__name = name  # Private attribute

          self.__salary = salary  # Private attribute

  

      def get_name(self):

          return self.__name

  

      def get_salary(self):

          return self.__salary

  

      def set_salary(self, new_salary):

          self.__salary = new_salary

  

  emp = Employee("Alice", 50000)

  print(emp.get_name())  # Output: Alice

  print(emp.get_salary())  # Output: 50000

  emp.set_salary(55000)

  print(emp.get_salary())  # Output: 55000

  ```


### Inheritance:

- Definition: Inheritance allows a class to inherit attributes and methods from another class, promoting code reusability and establishing an "is-a" relationship.

- Example:

  ```python

  class Vehicle:

      def __init__(self, make, model):

          self.make = make

          self.model = model

  

      def display_info(self):

          return f"{self.make} {self.model}"

  

  class Car(Vehicle):

      def __init__(self, make, model, color):

          super().__init__(make, model)

          self.color = color

  

      def display_info(self):

          return f"{self.color} {self.make} {self.model}"

  

  car = Car("Toyota", "Corolla", "Red")

  print(car.display_info())  # Output: Red Toyota Corolla

  ```


Define the following terms in DBMS

Attributes

Cardinality

Degree

Tuple


### Attributes:

- Definition: Attributes are the individual data elements that describe an entity. In a database table, attributes correspond to columns that represent specific characteristics or properties of the entity being modeled.

  

### Cardinality:

- Definition: Cardinality refers to the number of unique values that a column (attribute) can hold in a relational database table. It indicates the relationship between tables in a database by specifying the maximum number of related records that each record in a table can have in another table.

  

### Degree:

- Definition: Degree, also known as arity, refers to the number of attributes (columns) in a relation (table) within a relational database. It represents the total number of fields or data components in a tuple (row) of the relation.

  

### Tuple:

- Definition: In a relational database context, a tuple represents a single row or record in a table. It contains a set of attributes (columns) that encapsulate specific data related to an entity. Each tuple in a table represents a distinct instance or occurrence of the entity being modeled.


State and Explain five 5 advantages of Relational Model


### Advantages of Relational Model:


1. Data Integrity:

   - Explanation: The relational model enforces data integrity through constraints such as primary keys, foreign keys, and unique constraints. This ensures the accuracy, consistency, and reliability of data stored in the database.

  

2. Flexibility and Scalability:

   - Explanation: The relational model allows for flexible data retrieval and manipulation through SQL queries, enabling users to perform complex operations efficiently. Additionally, relational databases can easily scale to accommodate growing data volumes and evolving business requirements.

  

3. Normalization:

   - Explanation: The relational model promotes data normalization, reducing data redundancy and inconsistencies. By organizing data into related tables and eliminating duplicate information, it enhances data integrity and simplifies database maintenance.

  

4. Data Consistency:

   - Explanation: Relational databases ensure data consistency by enforcing ACID properties (Atomicity, Consistency, Isolation, Durability) during transactions. This guarantees that database operations are executed reliably and that data remains consistent even in concurrent access scenarios.

  

5. Query Optimization:

   - Explanation: Relational databases offer query optimization mechanisms, such as indexing, query plans, and execution plans. These tools enhance query performance by efficiently retrieving data from tables, minimizing processing time, and improving overall database performance.

Total Comments: 0

Meet the Author


PC
Emmanuel Amos Abanyie

Student teacher, Blogger

follow me

INTERSTING TOPICS


Connect and interact with amazing Authors in our twitter community