0% found this document useful (0 votes)
6 views4 pages

DBMS PR 3

The document outlines the creation of two tables, Students and Courses, with specified fields and data types. It includes SQL commands to insert 10 records into each table, add a new column to the Students table, modify the gender column, and query for specific student and course information. Additionally, it provides examples of SQL queries for retrieving data based on specific criteria.

Uploaded by

Arpita Siddhanti
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)
6 views4 pages

DBMS PR 3

The document outlines the creation of two tables, Students and Courses, with specified fields and data types. It includes SQL commands to insert 10 records into each table, add a new column to the Students table, modify the gender column, and query for specific student and course information. Additionally, it provides examples of SQL queries for retrieving data based on specific criteria.

Uploaded by

Arpita Siddhanti
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/ 4

3.

Create Tables:

Students student_id (INT, Primary Key) first_name (VARCHAR) last_name (VARCHAR)


gender (VARCHAR) email (VARCHAR)

Courses course_id (INT, Primary Key) course_name (VARCHAR) course_code (VARCHAR)


credits (INT)

NOTE:Insert 10 records

9. Write a query to add a new column phone_number (VARCHAR) to the Students table.

10. Write a query to modify the column gender in the Students table to gender (CHAR(1))
(i.e., store only the first letter of gender).

11. Write a query to find all students whose first name starts with the letter 'J'. Display
first_name, last_name, and email.

12. Write a query to find all courses that contain the word "Systems" in their name. Display
course_name, course_code, and credits.

CREATE TABLE Student2(

student_id INT PRIMARY KEY,

first_name VARCHAR(50),

last_name VARCHAR(50),

gender VARCHAR(10),

email VARCHAR(100)

);

INSERT INTO Student2 (student_id, first_name, last_name, gender, email) VALUES

(1, 'John', 'Doe', 'Male', '[email protected]'),


(2, 'Jane', 'Smith', 'Female', '[email protected]'),

(3, 'Michael', 'Brown', 'Male', '[email protected]'),

(4, 'Emily', 'Johnson', 'Female', '[email protected]'),

(5, 'Chris', 'Davis', 'Male', '[email protected]'),

(6, 'Sarah', 'Miller', 'Female', '[email protected]'),

(7, 'David', 'Wilson', 'Male', '[email protected]'),

(8, 'Laura', 'Taylor', 'Female', '[email protected]'),

(9, 'Daniel', 'Anderson', 'Male', '[email protected]'),

(10, 'Olivia', 'Thomas', 'Female', '[email protected]');

CREATE TABLE Courses2 (

course_id INT PRIMARY KEY,

course_name VARCHAR(100),

course_code VARCHAR(20)

);

-- Insert 10 records into Courses2

INSERT INTO Courses2 (course_id, course_name, course_code) VALUES

(1, 'Introduction to Computer Science', 'CS101'),

(2, 'Calculus I', 'MATH101'),

(3, 'Physics I', 'PHY101'),

(4, 'English Literature', 'ENG201'),

(5, 'World History', 'HIST101'),

(6, 'Chemistry I', 'CHEM101'),


(7, 'Principles of Economics', 'ECON101'),

(8, 'Psychology 101', 'PSY101'),

(9, 'Software Engineering', 'CS301'),

(10, 'Art Appreciation', 'ART101');

9. Write a query to add a new column phone_number (VARCHAR) to the Students


table.

ALTER TABLE Student1

ADD phone_number VARCHAR(20);

10. Write a query to modify the column gender in the Students table to gender (CHAR(1))

(i.e., store only the first letter of gender).

UPDATE Students

SET gender = SUBSTR(gender, 1, 1);

11. Write a query to find all students whose first name starts with the letter 'J'. Display

first_name, last_name, and email.

SELECT first_name, last_name, email

FROM Student1

WHERE first_name LIKE 'J%';

12. Write a query to find all courses that contain the word "Systems" in their name.
Display

course_name, course_code, and credits.

SELECT course_name, course_code, credits

FROM Courses1

WHERE course_name LIKE '%Systems%';

You might also like