Computer ScienceNEB 2082
Write any three differences between DDL and DML. Give examples of each. [3+2] OR What is normalization ? Explain 2NF and 3NF. [2+3]
5Answer
Differences between DDL and DML with Examples
| Feature | DDL (Data Definition Language) | DML (Data Manipulation Language) |
|---|---|---|
| Purpose | Used to define and modify the structure of database objects (tables, indexes, schemas, etc.). | Used to manipulate data stored in the database (insert, update, delete, retrieve). |
| Commands | CREATE, ALTER, DROP, TRUNCATE, RENAME |
SELECT, INSERT, UPDATE, DELETE, MERGE |
| Effect | Changes the database schema (logical structure) | Operates on existing data without altering the schema |
| Commit/Rollback | Does not support COMMIT or ROLLBACK (changes are permanent) |
Supports COMMIT and ROLLBACK (changes can be undone) |
| Example | CREATE TABLE Student (RollNo INT, Name VARCHAR(50)); |
INSERT INTO Student VALUES (1, 'Ram'); |
Examples:
DDL Example:
CREATE TABLE Student ( RollNo INT PRIMARY KEY, Name VARCHAR(50), Email VARCHAR(50) );- This command creates a new table called
Student.
- This command creates a new table called
DML Example:
INSERT INTO Student (RollNo, Name, Email) VALUES (1, 'Ram', 'ram@example.com');- This command inserts a new record into the
Studenttable.
- This command inserts a new record into the
Normalization, 2NF, and 3NF
What is Normalization?
Normalization is the process of organizing data in a database to minimize redundancy and dependency, ensuring data integrity. It involves dividing large tables into smaller, related tables and defining relationships between them.
Second Normal Form (2NF)
A table is in 2NF if:
- It is in 1NF (no repeating groups, atomic values).
- All non-key attributes are fully functionally dependent on the primary key (no partial dependencies).
Example:
Consider a table Enrollment with (StudentID, CourseID, Grade) as attributes.
- If
StudentIDis the primary key,CourseIDandGradedepend on bothStudentIDandCourseID(composite key). - If
StudentIDalone were the key,CourseIDwould be partially dependent (violating 2NF). - Solution: Split into two tables:
StudentCourse (StudentID, CourseID, Grade)Student (StudentID, Name, Address)
Third Normal Form (3NF)
A table is in 3NF if:
- It is in 2NF.
- There are no transitive dependencies (non-key attributes should not depend on other non-key attributes).
Example:
In the Student table above, if Address depends on City (which is also stored), it violates 3NF.
- Solution: Split into:
Student (StudentID, Name, City)City (City, Address)
Summary of Normalization Rules:
- 1NF: Atomic values, no repeating groups.
- 2NF: No partial dependencies (requires composite keys).
- 3NF: No transitive dependencies (non-key attributes depend only on the primary key).
Discussion
Loading…
More Computer Science questions
Which of the following is the purpose of using primary key in database ? a) To uniquely identify a record b) To store duplicate record c) To backup data d) To…NEB 2082 (MCQs)1A company needs to modify an existing table by adding a new column for employee email addresses. For this, which SQL command should be used ? a) CREATE b)…NEB 2082 (MCQs)1Which protocol is used for secure communication over a computer network ? a) HTTP b) FTP c) HTTPS d) TelnetNEB 2082 (MCQs)1Which control structure in JS (Java Script) is used to execute a block of code repeatedly based on a given condition ? a) For loop b) if else c) switch case…NEB 2082 (MCQs)1Select the invalid variable name in PHP. a) $name b) $ name c) $1name d) $name123NEB 2082 (MCQs)1The statement int number ( int a); is a ... a) function call b) function definition c) function declaration d) function executionNEB 2082 (MCQs)1