当前位置:网站首页>Database experiment I: data definition experiment guide
Database experiment I: data definition experiment guide
2022-06-12 05:47:00 【LEO-max】
Experiment 1 Data definition and experimental guidance
( Database schema design and establishment )
1. The experiment purpose
(1) Let students complete the design of database schema by themselves .
(2) use SQL Command to create database tables .
(3) Create database tables with visual environment .
2. Experimental content
(1) Define data table .
(2) Modify table structure : Add field , Modify field type .
(3) Delete table structure .
3. The experimental requirements
(1) Establish student database mode .
Student list :student (sno, sname, ssex, sage, sdept)
Student Student number full name Gender Age Department
sno The length is 4 String
sname The length is 8 String
ssex The length is 2 String
sage Short integer
sdept The length is 10 String
among sno Main code .
CREATE TABLE IF NOT EXISTS student(
sno VARCHAR(4) NOT NULL PRIMARY KEY COMMENT ' Student number , Primary key ',
sname VARCHAR(8) NOT NULL COMMENT ' full name ',
ssex VARCHAR(2) NOT NULL COMMENT ' Gender ',
sage TINYINT(3) UNSIGNED DEFAULT 0 COMMENT ' Age ',
sdept VARCHAR(10) NOT NULL COMMENT ' Department '
)ENGINE=InnoDB CHARSET=UTF8 COMMENT=' Student list ';
The curriculum :course ( cno, cname)
Course Course no. Course name credits
cno The length is 4 String
cname The length is 10 String
credit Short integer
among cno Main code .
CREATE TABLE IF NOT EXISTS course(
cno VARCHAR(4) NOT NULL PRIMARY KEY COMMENT ' Course no. , Primary key ',
cname VARCHAR(10) NOT NULL COMMENT ' Course name ',
credit TINYINT(3) UNSIGNED DEFAULT 0 COMMENT ' credits '
)ENGINE=InnoDB CHARSET=UTF8 COMMENT=' The curriculum ';
Course selection table : sc (sno, cno, cname, grade)
Course selection Student number Course no. Course name achievement
sno The length is 4 String
cno The length is 4 String
cname The length is 10 String
grade Short integer
among (sno, cno) Main code ;sno For outer code and student Table correspondence ;cno For outer code and course Table correspondence ;
grade The value of is either empty or 0—100 Between .
CREATE TABLE sc(
sno VARCHAR(4),
cno VARCHAR(4),
cname VARCHAR(10),
grade INT CHECK(grade BETWEEN 0 AND 100),
PRIMARY KEY (sno,cno),
FOREIGN KEY (sno) REFERENCES student(sno) ON DELETE CASCADE,
FOREIGN KEY (cno) REFERENCES course(cno)
)ENGINE=InnoDB CHARSET=UTF8;
(2) Modify data table structure
Add a... To the curriculum credit Field , Indicates credits , The type is short .
Delete... From the course selection list cname Field .
ALTER TABLE course MODIFY credit TINYINT COMMENT ' credits ';
ALTER TABLE sc drop cname;
(3) Undo data table . Create a temporary table , Then undo it .
CREATE TABLE TEMP(
cno VARCHAR(4) PRIMARY KEY,
cname VARCHAR(10),
credit TINYINT
);
DROP TABLE temp;
Ask to write all the code of Experiment 1 ,
Be careful :
1. All the code
2. The full width of the code
3. Regular format , Easy to read
边栏推荐
猜你喜欢
随机推荐
Chapter 8 - structure
[untitled]
什么是工程预付款
从传统网络IO 到 IO多路复用
Analysis of pointer
Introduction to thread pool: ThreadPoolExecutor
Win10 desktop unlimited refresh
Role and understanding of proc/cmdline
数据集成框架SeaTunnel学习笔记
Conversion of Halcon 3D depth map to 3D image
The application could not be installed: INSTALL_FAILED_TEST_ONLY
merge sort
Is the individual industrial and commercial door a legal person enterprise
A solution for PHP to implement image login verification code
RTMP streaming +rtmp playback low delay solution in unity environment
yolov5
FPGA语法的细节
Chapter 7 - pointer learning
How much Ma is the driving current of SIM card signal? Is it adjustable?
C WMI query remote Win32_ Operatingsystem class









