Still Thinking Of Assignment Help & Grades ? Book Your Assignment At The Lowest Price Now & Secure Higher Grades! CALL US +91-9872003804
Order Now
Value Assignment Help

Assignment sample solution of DBMS300 - SQL Programming Basics

Question 1: What is a primary key in a database, and why is it important?

Question 2: Explain the difference between DELETE and TRUNCATE in SQL.

Question 3: What is a JOIN in SQL, and how is it used?

  1. 1
  2. 2

Database Assignment Sample

Q1:

Answer :

A primary key is a unique identifier for records in a database table, ensuring each row is distinct. For example, StudentID in a Students table.
Importance:

  • Uniqueness: Prevents duplicate entries.
  • Indexing: Automatically indexed, improving query performance.
  • Data Integrity: Ensures accurate identification and relationships between tables.
  • Referential Integrity: Used as a reference in foreign keys for relational integrity.
    Primary keys are fundamental for structured and consistent data management.

Q1:

Answer :

Both DELETE and TRUNCATE remove data, but their usage differs:

  • DELETE: Removes specific rows based on conditions. Allows rollback with WHERE clause. Example: DELETE FROM Students WHERE Age > 20;
  • TRUNCATE: Removes all rows in a table, resetting auto-increment counters. Cannot be rolled back. Example: TRUNCATE TABLE Students;
    DELETE is more flexible for selective deletions, while TRUNCATE is faster for bulk deletions without conditions.

Q1:

Answer :

A JOIN combines data from multiple tables based on related columns. Common types:

  • INNER JOIN: Retrieves matching rows.
  • LEFT JOIN: Includes all rows from the left table and matching rows from the right.
  • RIGHT JOIN: Opposite of LEFT JOIN.
  • FULL JOIN: Includes all rows with matching or null values.

Example:

SELECT Students.Name, Courses.CourseName
FROM Students
INNER JOIN Enrollments ON Students.StudentID = Enrollments.StudentID;