sql基础语句
创建学生表
CREATE TABLE table_student(
STUDENTID INT PRIMARY KEY,
SNAME CHAR(5) NOT NULL,
AGE INT ,
SEX INT CHECK(SEX IN(1,2))
)
-------------------------------
创建教师表
CREATE TABLE table_teacher(
TEACHERID INT PRIMARY KEY,
TNAME CHAR(5) NOT NULL
)
--------------------------------
创建课程表
CREATE TABLE table_course(
COURSEID INT PRIMARY KEY,
CNAME CHAR(5),
TID INT ,
CONSTRAINT FK_TID FOREIGN KEY (TID) REFERENCES table_teacher(TEACHERID)
)
-------------------------------
创建成绩表
CREATE TABLE table_grade(
STUDENTID INT ,
COURSEID INT ,
SCORE INT,
PRIMARY KEY(STUDENTID,COURSEID)
)
-------------------------------------
创建自增序列表
CREATE TABLE table_home(
HOMEID INT PRIMARY KEY AUTO_INCREMENT,
HOMENAME CHAR(5)
)
----------------------------------------
数据的插入
INSERT INTO table_home(HOMENAME) VALUES('ZXBIN')
------------------------------------------------
数据查询
SELECT * FROM table_home
------------------------------------------------
STUDENTID INT PRIMARY KEY,
SNAME CHAR(5) NOT NULL,
AGE INT ,
SEX INT CHECK(SEX IN(1,2))
)
-------------------------------
创建教师表
CREATE TABLE table_teacher(
TEACHERID INT PRIMARY KEY,
TNAME CHAR(5) NOT NULL
)
--------------------------------
创建课程表
CREATE TABLE table_course(
COURSEID INT PRIMARY KEY,
CNAME CHAR(5),
TID INT ,
CONSTRAINT FK_TID FOREIGN KEY (TID) REFERENCES table_teacher(TEACHERID)
)
-------------------------------
创建成绩表
CREATE TABLE table_grade(
STUDENTID INT ,
COURSEID INT ,
SCORE INT,
PRIMARY KEY(STUDENTID,COURSEID)
)
-------------------------------------
创建自增序列表
CREATE TABLE table_home(
HOMEID INT PRIMARY KEY AUTO_INCREMENT,
HOMENAME CHAR(5)
)
----------------------------------------
数据的插入
INSERT INTO table_home(HOMENAME) VALUES('ZXBIN')
------------------------------------------------
数据查询
SELECT * FROM table_home
------------------------------------------------