DBMS 1
DBMS 1
- Data consistency: DBMS ensures that data remains consistent across the database by enforcing
integrity constraints.
- Data sharing: Multiple users can access and modify data concurrently without conflicts, unlike in a
file system.
- Security: DBMS provides access control mechanisms to regulate who can access and manipulate
the data, enhancing security.
- Data integrity: With built-in features like transactions and ACID properties, DBMS maintains the
accuracy and reliability of data.
- Data independence: Changes to the database structure do not affect the applications interacting
with the data, ensuring flexibility and ease of maintenance.
- Presentation layer: Interfaces with users, displaying information and receiving inputs.
- Application layer: Contains business logic and processing functions, translating user requests into
database operations.
- Data layer: Stores and manages the actual data, handling storage, retrieval, and manipulation
operations.
3. **Explain ER Model:**
- Entity-Relationship (ER) model: A conceptual framework for representing data entities, attributes,
and relationships.
- Relationships: Describe associations between entities, indicating how they are related to each
other.
- Relation mapping involves translating the ER model's entities, relationships, and attributes into
relational database tables, columns, and keys.
- Each entity becomes a table, each attribute becomes a column, and each relationship becomes a
foreign key constraint.
- The process ensures that the structure of the database reflects the conceptual model represented
by the ER diagram.
- Proper mapping facilitates efficient data storage, retrieval, and manipulation operations.
- Relation mapping is crucial for maintaining data integrity and consistency within the database.
```
emp_age INT,
emp_sal DECIMAL(10,2)
);
```
- emp_name: Not null constraint ensures that the employee's name is always provided.
- emp_add: Not null constraint ensures that the employee's address is always provided.
6. **Add column emp_add into the above table and Rename the table name as emp_details:**
```
```
- Data Definition Language (DDL) commands are used to define, modify, and remove database
objects such as tables, views, and indexes.
- Simple attribute: Represents a single atomic value, such as an employee's age or salary.
- Derived attribute: Derived from other attributes, calculated based on existing attributes, such as
age derived from the employee's date of birth.
- Multi-valued attribute: Can hold multiple values for an entity, such as an employee's phone
numbers.
- Normalize the schema if necessary to remove redundancies and improve data integrity.
- Relationships: Treats (between Doctor and Patient), Works in (between Doctor/Nurse and
Department), etc.
- Database administration involves managing and maintaining the database system to ensure its
smooth operation.
- Responsibilities include performance tuning, security management, backup and recovery, and
user access control.
- DBA monitors database performance, troubleshoots issues, and optimizes database structures.
- DBA plays a crucial role in planning and implementing database upgrades, migrations, and
scaling.
- Aggregate functions perform calculations on a set of values and return a single value.
- Example: SELECT SUM(salary) FROM employee; (Calculates the total salary of all employees)
- Integrity constraints are rules that enforce data integrity and consistency in a database.
- Example: CREATE TABLE employee (emp_id INT PRIMARY KEY, emp_name VARCHAR(50) NOT
NULL); (Defines emp_id as the primary key and ensures emp_name is not null)
a) **Selection operation:**
b) **Projection Operator:**
- Helps in selecting only the required information, reducing data retrieval overhead.
- Retrieves only the rows that have matching values in both tables.
- Outer join retrieves all records from one table and the matching records from another table.
- Preserves unmatched rows from one or both tables in the result set.
- Types: LEFT OUTER JOIN, RIGHT OUTER JOIN, FULL OUTER JOIN.
- Useful for including non-matching rows in the result set for analysis.
- ANY and ALL operators compare a value to a set of values returned by a subquery.
- ANY returns true if any value in the set satisfies the comparison.
- ALL returns true if all values in the set satisfy the comparison.
- EXISTS operator checks for the existence of any rows in a subquery result.
- Example: SELECT * FROM products WHERE price > ANY (SELECT price FROM discounts);
- Relational constraints are rules applied to maintain data integrity in a relational database.
- Examples: Entity integrity, referential integrity, domain integrity.
- Entity integrity ensures that each row in a table is unique and has a primary key.
- Referential integrity ensures that relationships between tables are maintained through foreign
key constraints.
- Domain integrity ensures that data values adhere to specified data types, ranges, or formats.
- Relational algebra operations are mathematical operations used to manipulate relational data.
- Operations include Selection, Projection, Union, Intersection, Difference, Join, and Cartesian
Product.
- Relational algebra provides a theoretical foundation for querying and manipulating relational
databases.
- These operations help in performing various data retrieval and manipulation tasks efficiently.
- Cross product combines each row of the first table with each row of the second table.
- Resulting in a Cartesian product, where every combination of rows from both tables is included.
- Joins are SQL operations used to combine data from two or more tables based on related
columns.
- Different types of joins include INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN.
- Joins allow for querying related data from multiple tables in a single query.
24. **Explain Date Function with example:**
- Date functions manipulate date and time values stored in the database.
- Inner Join: Retrieves rows that have matching values in both tables.
- Left Join: Retrieves all rows from the left table and matching rows from the right table.
- Right Join: Retrieves all rows from the right table and matching rows from the left table.
- Full Join: Retrieves all rows from both tables, including unmatched rows from each table.
- Categories of functions include String functions, Numeric functions, Date functions, Aggregate
functions, Conversion functions, etc.
- Views are virtual tables derived from one or more base tables.
- Views do not store data themselves but provide a dynamic result set based on the underlying
tables.
- Advantages of views:
1. Data security: Views can restrict access to specific columns or rows, enhancing security.
2. Simplified querying: Views abstract complex SQL queries, making them easier to write and
understand.
3. Data abstraction: Views hide the underlying table structure, providing a layer of abstraction to
users.
4. Performance optimization: Views can precompute aggregated data or filter rows, improving
query performance.
- An index is a database object that improves the speed of data retrieval operations on a table.
1. Primary index: Automatically created when defining a primary key constraint. Used to enforce
uniqueness and speed up primary key lookups.
2. Unique index: Ensures that the indexed columns contain unique values, similar to a primary key
constraint.
3. Clustered index: Organizes table data physically based on the indexed columns, improving
range scans and sequential access.
4. Non-clustered index: Creates a separate structure from the table data, allowing for efficient
lookups and sorting operations.
2. Software failure: Bugs, crashes, or compatibility issues in the database management system or
related software.
4. Natural disasters: Events like earthquakes, floods, or fires that damage physical infrastructure.
- Causes of failure vary in severity and impact on the database system's availability, integrity, and
performance.
3. Backup and recovery: Developing and executing backup strategies to ensure data availability
and disaster recovery.
4. User management: Creating and managing user accounts, permission and roles to control
access to data and resources.
- Foreign Key:
1. Links a table with another table's primary key to establish relationships.
2. Enforces referential integrity, ensuring that values in the referencing table correspond to
values in the referenced table.
3. Helps maintain data consistency across related tables.
4. Can contain NULL values unless specified as NOT NULL.
5. Example: DepartmentID in an employee table referencing DepartmentID in a department
table.
- Candidate Key:
1. A set of attributes that can uniquely identify tuples in a relation.
2. Similar to the primary key but not chosen as the primary key.
3. Each candidate key is unique within the relation.
4. Can become the primary key if chosen by the database designer.
5. Example: Both SSN (Social Security Number) and EmployeeID could be candidate keys in
an employee table.
- Super Key:
1. A set of attributes that uniquely identifies a tuple within a relation.
2. May include more attributes than necessary to uniquely identify a tuple.
3. Any subset of a super key is also a super key.
4. Can be a combination of candidate keys and other attributes.
5. Example: A combination of EmployeeID and Email in an employee table.
- Alternate Key:
1. A candidate key that is not selected to be the primary key.
2. Can uniquely identify tuples but is not chosen as the primary means of identification.
3. Exists alongside the primary key in a relation.
4. Example: Phone number in an employee table could be an alternate key if not chosen as the
primary key.
5. Used for querying and referencing tuples but does not hold the primary identifier status.
- **Deleting a view:**
```sql
DROP VIEW view_name;
```
- view_name: Name of the view to be deleted.
value.
- Examples include SUM(), AVG(), COUNT(), MAX(), and MIN().
- Used with the GROUP BY clause to calculate values for groups of rows.
- Example: SELECT SUM(salary) FROM employee; (Calculates the total salary of all employees)
44. **Key Constraints:**
- Key constraints enforce rules related to keys in a database table.
- Examples include PRIMARY KEY, FOREIGN KEY, UNIQUE, NOT NULL.
- PRIMARY KEY constraint ensures uniqueness and identifies a unique record in a table.
- FOREIGN KEY constraint establishes relationships between tables based on a primary key
and foreign key relationship.
- UNIQUE constraint ensures that values in a column or a combination of columns are unique.
- NOT NULL constraint ensures that a column does not contain NULL values.