-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path30_01_2025.sql
52 lines (42 loc) · 1.34 KB
/
30_01_2025.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
-- Database operations
SHOW DATABASES;
CREATE DATABASE UniversityDB;
USE UniversityDB;
-- Create Students table with proper constraints
CREATE TABLE ComputerScienceStudents (
student_id INT PRIMARY KEY,
student_name VARCHAR(50) NOT NULL,
exam_score INT CHECK (exam_score BETWEEN 0 AND 100),
country VARCHAR(50) DEFAULT 'India'
);
-- Insert sample records
INSERT INTO ComputerScienceStudents VALUES
(1001, 'Ram Prasad', 99, DEFAULT),
(1002, 'Priya Sharma', 100, DEFAULT),
(1003, 'Anjali Patel', 95, DEFAULT),
(1004, 'Rahul Verma', 98, DEFAULT),
(1005, 'Neha Gupta', 94, DEFAULT);
-- View all students
SELECT * FROM ComputerScienceStudents;
-- Table modifications
ALTER TABLE ComputerScienceStudents ADD (
contact_number VARCHAR(15)
);
-- View table structure
DESCRIBE ComputerScienceStudents;
-- Remove contact column
ALTER TABLE ComputerScienceStudents DROP COLUMN contact_number;
-- Add admission date column
ALTER TABLE ComputerScienceStudents ADD (
admission_date DATE DEFAULT CURRENT_DATE
);
-- Insert student with different country
INSERT INTO ComputerScienceStudents VALUES
(1006, 'Aarav Singh', 92, 'USA', DEFAULT);
-- View final student list
SELECT student_id AS ID,
student_name AS Name,
exam_score AS Score,
country AS Country
FROM ComputerScienceStudents
ORDER BY exam_score DESC;