SQL Server数据库学习之 -- 常用语句二
扫描二维码
随时随地手机看文章
-- 引用数据库 USE [School01] GO SET ANSI_NULLS ON -- 设置编码格式 GO SET QUOTED_IDENTIFIER ON GO -- 创建学生表 tb_student CREATE TABLE tb_student ( Sno CHAR(3) PRIMARY KEY NOT NULL, Sname CHAR(8) NOT NULL, Ssex CHAR(2) NOT NULL, Sbirthday DATETIME, Class CHAR(5) ) GO -- 创建教师表 tb_teacher CREATE TABLE tb_teacher ( Tno char(3) PRIMARY KEY NOT NULL, Tname char(4) NOT NULL, Tsex char(2) NOT NULL, Tbirthday datetime, Profession char(6), Depart varchar(10) NOT NULL ) GO -- 创建课程表 tb_course CREATE TABLE tb_course ( Cno char(5) PRIMARY KEY NOT NULL, Cname varchar(10) NOT NULL, Tno char(3) NOT NULL, FOREIGN KEY (Tno) REFERENCES tb_teacher(Tno) -- 外键约束 ) GO CREATE TABLE tb_score ( Sno char(3) NOT NULL, Cno char(5) NOT NULL, Degree Decimal(4,1), FOREIGN KEY (Sno) REFERENCES tb_student(Sno), -- 外键约束 FOREIGN KEY (Cno) REFERENCES tb_course(Cno) -- 外键约束 )