0% found this document useful (0 votes)
3 views3 pages

DBMS COdes

The document is a preparation guide for DBMS lab viva, covering key concepts such as DBMS definition, SQL table creation with primary and foreign keys, basic SQL operations, and examples of joins and views. It also includes a case study on a Library Management System with relevant SQL schema and sample queries. The guide serves as a comprehensive resource for understanding and practicing essential DBMS functionalities.

Uploaded by

gbeast595
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

DBMS COdes

The document is a preparation guide for DBMS lab viva, covering key concepts such as DBMS definition, SQL table creation with primary and foreign keys, basic SQL operations, and examples of joins and views. It also includes a case study on a Library Management System with relevant SQL schema and sample queries. The guide serves as a comprehensive resource for understanding and practicing essential DBMS functionalities.

Uploaded by

gbeast595
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

DBMS Lab Viva Preparation Guide

1. Important Viva Questions with SQL Examples

What is DBMS?
DBMS stands for Database Management System. It is software for storing and managing
data efficiently.

How to CREATE a table with PRIMARY KEY?


CREATE TABLE Students (
student_id INT PRIMARY KEY,
name VARCHAR(50),
age INT
);

How to create a table with FOREIGN KEY?


CREATE TABLE Courses (
course_id INT PRIMARY KEY,
course_name VARCHAR(50)
);

CREATE TABLE Enrollments (


student_id INT,
course_id INT,
FOREIGN KEY (student_id) REFERENCES Students(student_id),
FOREIGN KEY (course_id) REFERENCES Courses(course_id)
);

Basic SQL Operations:


INSERT INTO Students (student_id, name, age)
VALUES (1, 'John', 20);

SELECT * FROM Students;

UPDATE Students
SET age = 21
WHERE student_id = 1;

DELETE FROM Students


WHERE student_id = 1;
ALTER table (add/delete column, add keys):
ALTER TABLE Students ADD email VARCHAR(100);
ALTER TABLE Students DROP COLUMN email;
ALTER TABLE Students ADD PRIMARY KEY (student_id);
ALTER TABLE Enrollments ADD CONSTRAINT fk_student FOREIGN KEY (student_id)
REFERENCES Students(student_id);

Joins Example:
SELECT Students.name, Courses.course_name
FROM Students
JOIN Enrollments ON Students.student_id = Enrollments.student_id
JOIN Courses ON Enrollments.course_id = Courses.course_id;

View Example:
CREATE VIEW StudentCourses AS
SELECT Students.name, Courses.course_name
FROM Students
JOIN Enrollments ON Students.student_id = Enrollments.student_id
JOIN Courses ON Enrollments.course_id = Courses.course_id;

Transactions:
START TRANSACTION;

UPDATE Students SET age = 22 WHERE student_id = 1;


DELETE FROM Enrollments WHERE student_id = 1;

COMMIT;

2. Case Study Example: Library Management System


Entities: Books, Members, Borrow

SQL Schema:

CREATE TABLE Books (


book_id INT PRIMARY KEY,
title VARCHAR(100),
author VARCHAR(50)
);

CREATE TABLE Members (


member_id INT PRIMARY KEY,
name VARCHAR(50),
join_date DATE
);

CREATE TABLE Borrow (


borrow_id INT PRIMARY KEY,
book_id INT,
member_id INT,
borrow_date DATE,
FOREIGN KEY (book_id) REFERENCES Books(book_id),
FOREIGN KEY (member_id) REFERENCES Members(member_id)
);

Sample Query: List all borrowed books

SELECT Members.name, Books.title, Borrow.borrow_date


FROM Borrow
JOIN Members ON Borrow.member_id = Members.member_id
JOIN Books ON Borrow.book_id = Books.book_id;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy