DBMS-1
DBMS-1
Used to define and modify the database structure. Used to manipulate data within the database.
Examples: CREATE, ALTER, DROP, TRUNCATE, RENAME
Examples: SELECT, INSERT, UPDATE, DELETE.
.
Deals with database schema and metadata. Deals with actual data stored in tables.
Commands are auto-committed (changes are saved
Commands are not auto-committed (can be rolled back).
permanently).
Defines the structure of database objects like tables,
Performs operations on the data stored in the database objects.
indexes, and constraints.
Typically used by database administrators (DBAs). Typically used by developers and end-users.
Changes the structure of the database. Changes the content of the database.
Commit Rollback
Saves changes made during the current Reverts changes made during the current transaction, restoring the
transaction permanently to the database. database to its previous state.
Used to confirm and apply changes. Used to undo changes in case of errors or issues.
Once committed, changes cannot be undone. Rollback is only possible before a commit is executed.
Syntax (in SQL): COMMIT; Syntax (in SQL): ROLLBACK;
Ensures data consistency and permanence. Ensures data integrity by discarding unwanted or erroneous changes.
Typically used after a successful transaction. Typically used when a transaction fails or needs to be canceled.
Example: After inserting, updating, or deleting Example: If an error occurs during a transaction, rollback undoes the
records, commit makes the changes permanent. changes.
Removes specific rows from a table Removes all rows from a table, but the Deletes the entire table structure and
based on a condition. table structure remains intact. data from the database.
Can be rolled back (if used within a Cannot be rolled back (in most Cannot be rolled back.
transaction). databases).
Slower than TRUNCATE because it logs Faster than DELETE because it Removes the table and its metadata
each row deletion. deallocates entire data pages. completely.
Requires a WHERE clause to specify Does not require a WHERE clause. Does not require a WHERE clause.
rows to delete.
Does not reset the identity/auto- Resets the identity/auto-increment Removes the table entirely, including
increment value. value. auto-increment values.
Example: DELETE FROM table_name Example: TRUNCATE TABLE Example: DROP TABLE table_name;
WHERE condition; table_name;
A DBMS (Database Management System) is a software system that allows users to define, create, maintain, and control
access to databases. It serves as an interface between the database and end-users or application programs, ensuring that data
is organized, accessible, and secure. Examples of DBMS include MySQL, Oracle, PostgreSQL, and MongoDB.
Advantages of DBMS:
1. Data Centralization: All data is stored in a single repository, eliminating data redundancy and inconsistency.
2. Data Sharing: Multiple users and applications can access the same data simultaneously, improving collaboration.
3. Data Integrity: Ensures accuracy and consistency of data through constraints, validations, and rules.
4. Data Security: Provides user authentication, authorization, and encryption to protect sensitive data.
5. Data Backup and Recovery: Automates backup processes and ensures data recovery in case of failures or
crashes.
6. Data Abstraction: Hides the complexity of the database structure from users, providing a simplified view.
7. Concurrency Control: Manages simultaneous access to the database to prevent conflicts and ensure data
consistency.
8. Improved Decision-Making: Provides tools for data analysis and reporting, enabling better decision-making.
9. Reduced Data Redundancy: Minimizes duplicate data by storing it in a centralized location.
10. Scalability: Supports the growth of data and users without compromising performance.
11. Data Independence: Separates the logical and physical views of data, allowing changes to one without affecting the
other.
12. Ease of Use: Provides user-friendly interfaces and query languages (e.g., SQL) for managing data.
ACID stands for Atomicity, Consistency, Isolation, and Durability. These properties ensure reliable processing of database
transactions, maintaining data integrity even in cases of system failures, power outages, or errors.
1. Atomicity: A transaction is considered atomic if it is treated as a single unit of work. If any part of the transaction
fails, the entire transaction is rolled back, and the database remains unchanged.
Example: A bank transfer involves debiting one account and crediting another. If either operation fails, the entire
transaction is canceled.
2. Consistency: Ensures that the database remains in a consistent state before and after the transaction. All data must
follow predefined rules, such as constraints, triggers, and cascades.
Example: If a transaction violates a constraint, it is rolled back to maintain consistency.
3. Isolation: Ensures that concurrent transactions do not interfere with each other. Transactions are executed in
isolation, as if they were running one after the other.
Example: If two transactions are updating the same data, one transaction will wait for the other to complete before
proceeding.
4. Durability: Ensures that once a transaction is committed, its effects are permanent and survive system failures.
Changes are saved to non-volatile storage (e.g., disk) and cannot be lost.
Example: After a successful bank transfer, the changes to the account balances are permanent, even if the system
crashes immediately afterward.