Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
Copy Format Clear
-- Create the Departments table CREATE TABLE Departments ( DepartmentID INT PRIMARY KEY, DepartmentName VARCHAR(100) NOT NULL ); -- Create the Students table CREATE TABLE Students ( StudentID INT PRIMARY KEY, FirstName VARCHAR(50) NOT NULL, LastName VARCHAR(50) NOT NULL, DateOfBirth DATE, Gender VARCHAR(10), DepartmentID INT, FOREIGN KEY (DepartmentID) REFERENCES Departments(DepartmentID) ); -- Create the Courses table CREATE TABLE Courses ( CourseID INT PRIMARY KEY, CourseName VARCHAR(100) NOT NULL, Credits INT CHECK (Credits >= 0) ); -- Create the Enrollments table CREATE TABLE Enrollments ( EnrollmentID INT PRIMARY KEY, StudentID INT, CourseID INT, EnrollmentDate DATE, Grade VARCHAR(5), FOREIGN KEY (StudentID) REFERENCES Students(StudentID), FOREIGN KEY (CourseID) REFERENCES Courses(CourseID) ); -- a) Add a new column 'Email' to the Students table ALTER TABLE Students ADD Email VARCHAR(100); -- b) Modify the 'Gender' column to accept 'Male' and 'Female' ALTER TABLE Students MODIFY Gender VARCHAR(10); -- c) Rename the 'Courses' table to 'Subjects' RENAME TABLE Courses TO Subjects;

Stuck with a problem? Got Error? Ask AI support!

Copy Clear