資料庫SQL語句實現

2021-06-13 14:01:16 字數 2604 閱讀 7670

1、建立資料庫

create database if not exists cs2013;

2、建立資料庫**

create table if not exists comp (

id int not null primary key auto_increment ,

pid varchar(30) not null unique ,

cname varchar(30) not null ,

ename varchar(30) not null ,

grade varchar(30) not null ,

*** int not null ,

clothe varchar(15) not null

)default charset = utf8;

create table if not exists team (

id int not null primary key auto_increment ,

cname varchar(30) not null ,

ename varchar(30) not null ,

coach0 int not null ,

coach1 int not null ,

stu0 int not null ,

stu1 int not null ,

stu2 int not null ,

isgirls int not null ,

email varchar(30) not null ,

phone varchar(15) not null ,

foreign key (coach0) references comp(id) ,

foreign key (coach1) references comp(id) ,

foreign key (stu0) references comp(id) ,

foreign key (stu1) references comp(id) ,

foreign key (stu2) references comp(id)

)default charset = utf8;

create table if not exists college (

id int not null primary key auto_increment,

cname varchar(30) not null ,

ename varchar(30) not null ,

teamcnt int not null

)default charset = utf8;

create table if not exists rc (

id int not null primary key auto_increment ,

college int not null ,

team int not null ,

date date not null ,

foreign key (college) references college (id) ,

foreign key (team) references team (id)

)default charset = utf8;

create table if not exists room (

id int not null primary key auto_increment,

name varchar(30) not null ,

totcnt int not null ,

regcnt int not null ,

price double not null

)default charset = utf8;

create table if not exists hotel (

id int not null primary key auto_increment,

name varchar(30) not null ,

room0 int not null ,

room1 int not null ,

room2 int not null ,

foreign key (room0) references room (id) ,

foreign key (room1) references room (id) ,

foreign key (room2) references room (id)

)default charset = utf8;

create table if not exists rh (

id int not null primary key auto_increment,

college int not null ,

hotel int not null ,

date date not null ,

foreign key (college) references college (id) ,

foreign key (hotel) references hotel (id)

)default charset = utf8;

SQL資料庫SQL語句實現行轉列

最近負責的模組設計到統計,由於前期設計思路比較清晰,在統計這塊,只需要從資料庫中統計出相關資料庫就可以了。統計表 表頭 檔案型別 所選年份 1 12月份 但是直接出去來的資料,無法直接在頁面上展示 img 執行語句 select count as totalcount,archivetype,mon...

資料庫 SQL語句

在sql語言中,我們可以通過create database去建立資料庫,語法格式如下所示 create database 資料庫名 就比如我們可以建立乙個學校資料庫 create database schooldb 建立表的操作 create table 表名稱 列名稱1 資料型別,列名稱2 資料型...

SQL語句建立資料庫

1.create database dataname 這是建立資料庫最簡單的方法 資料庫的各個屬性都是預設 如資料庫檔案與日誌檔案儲存目錄 資料庫大小等 下面介紹下常用決定資料庫屬性的子句 on 簡單理解為定義儲存資料庫檔案的位置,看下面 filename 資料庫的邏輯別名 size 資料庫初始大小...