Table of contents
2. Level 2: Modify the table structure
Data structure description (ie table structure)
1. Level 1: Create a table
1.1 Task description
Use the create table statement in the SQL language to create Student, Course, and SC tables.
1.2 SQL statement
CREATE TABLE Student(
Sno char(10) PRIMARY KEY,
Sname varchar(20),
Ssex char(2),
Sage smallint,
Sdept varchar(20)
);
CREATE TABLE Course(
Cno char(10) PRIMARY KEY,
Cname varchar(20),
Cpno char(10),
Ccredit smallint
);
CREATE TABLE SC(
Sno char(10),
Cno char(10),
Grade smallint,
PRIMARY KEY(Sno,Cno)
);
2. Level 2: Modify the table structure
2.1 Task description
Use the alter table statement in the SQL statement to modify the table structure:
1. Add a column ( lowercase column name ) to the Student table: phone char(12);
2. Delete the Cpno column in the Course table;
3. Change the sdept column of the Student table to: sdept varchar(30).
2.2 SQL statements
ALTER TABLE Student ADD phone char(12);
ALTER TABLE Course DROP COLUMN Cpno;
ALTER TABLE Student ADD phone char(12);
3. Level 3: Delete table
3.1 Task description
Use the Drop table statement in the SQL statement to delete the table structure:
Delete the Student, Course and SC tables. (The SC table has external codes, please pay attention to the order of deletion)
3.2 SQL statement
DROP TABLE SC;--有外码的表优先被删除
DROP TABLE Student;
DROP TABLE Course;