SQL 資料庫新建學生資訊表及插入資料

2021-08-20 08:47:41 字數 1573 閱讀 3690

學生表:包括學號,姓名,性別,年齡,專業

create table student

(student_id varchar(7)primary key,

student_name varchar(10)not null,

student_*** varchar(2) check(student_***='男'or student_***='女'),

student_age int check(student_age between 15 and 45),

student_dept varchar(20)default('計算機系')

插入學生表資料:

insert into student values('100','張一','男',19,'計算機') /*按照表的順序依次寫入*/

insert into student(student_id,student_name ,student_*** ,student_age) values('101','張ii','男',15)  /*預設為計算機系*/

課程表:包括課程號,課程名,學時,學分

create table course

(course_id varchar(10)primary key,

course_name varchar (20)not null,

course_hours int check(course_hours>0),

course_credit int check(course_credit>0)

插入課程表資料:

insert into course values('201803','漢語國際教育',18,5)

選課表:包括學號,課程號,成績

create table choosecouse

(student_id varchar(7) foreign key references student(student_id),

course_id varchar(10)foreign key references course(course_id),

primary key(student_id,course_id),

score int check(score between 0 and 100)

插入選課表資料:

覺得不錯請打賞,您的十分滿意是筆者的無線動力

學生資訊資料庫

create database 學生資訊資料庫 gouse 學生資訊資料庫 gocreate table 課程資訊表 課程號 int not null,課程名稱 char 20 not null,學分 int not null create table 學生資訊表 學號 int not null,姓...

SQL查詢資料庫資訊, 資料庫表名, 資料庫表資訊

sql查詢資料庫資訊,資料庫表名,資料庫表資訊 以下例子,在sql server 中可以直接執行,預設資料庫為master 獲取資料庫的所有使用者名稱 select from sysusers where islogin 1 1.獲取所有的資料庫名 select name from master.s...

OSCAR神通資料庫建表及插資料

一 建表 create table oscar表名 t id bigint not null,t date date,t time time 6 t timestamp timestamp 6 t serial serial,t bigserial bigserial,constraint tbl ...