MySQL5.7: sql script demo
程序员文章站
2022-04-11 08:28:36
/* CREATE DATABASE geovindu DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci; use geovindu; */ -- 查詢編碼格式 show variables like '%char%'; -- SE... ......
/*
create database geovindu
default character set utf8
default collate utf8_general_ci;
use geovindu;
*/
-- 查詢編碼格式
show variables like '%char%';
-- set names gb2312;
alter database geovindu
default character set utf8
default collate utf8_general_ci;
-- 修改數据的編碼格式
alter database geovindu
default character set utf8
-- default character set=utf8
-- default character set server=utf8
-- default collation server=utf8_general_ci
default collate utf8_general_ci;
-- 設置
set character_set_server = utf8;
set character_set_results=gb2312;
set character_set_database = latin1;
select 'host' from user; -- where user='root';
/*
szcentilc.com
'character_set_client', 'utf8'
'character_set_connection', 'utf8'
'character_set_database', 'latin1'
'character_set_filesystem', 'binary'
'character_set_results', 'utf8'
'character_set_server', 'latin1'
'character_set_system', 'utf8'
20180709
character_set_client utf8
character_set_connection utf8
character_set_database utf8
character_set_filesystem binary
character_set_results utf8
character_set_server latin1
character_set_system utf8
*/
/*
原始的
character_set_client utf8
character_set_connection utf8
character_set_database latin1 -- phpmyadmin2 客戶查詢亂碼
character_set_filesystem binary
character_set_results utf8
character_set_server latin1
character_set_system utf8
mysql> set character_set_client = utf8 ;
mysql> set character_set_connection = utf8 ;
mysql> set character_set_database = utf8 ;
mysql> set character_set_results = utf8 ;
mysql> set character_set_server = utf8 ;
mysql> set collation_connection = utf8 ;
mysql> set collation_database = utf8 ;
mysql> set collation_server = utf8 ;
*/
show databases;
show databases; -- 列出 mysql server 上的資料庫。
show tables from test; -- 列出資料庫的資料表。
show table status from test; -- 列出資料庫的資料表,提供比較詳細的訊息。
show columns from test; -- 列出資料表的欄位,同 show fields from tbl_name [from db_name],describe tbl_name [col_name]。
show full columns from test; -- 列出資料表的欄位,提供比較詳細的訊息,同 show full fields from tbl_name [from db_name]。
show index from test; -- 列出資料表的索引訊息。
show status; -- 列出 server 的狀態訊息。
show variables; -- 列出 mysql 系統變數的值。
show processlist; -- 顯示哪個執行緒正在運行。
show grants for user; -- 列出對一個用戶必須發出以重複授權的授權命令
-- 主键
select * from information_schema.key_column_usage;
-- https://dev.mysql.com/doc/refman/8.0/en/keywords-table.html
select * from information_schema.keywords;
select * from information_schema.keywords;
select
concat(table_name, '.', column_name) as 'foreign key',
concat(referenced_table_name, '.', referenced_column_name) as 'references'
from
information_schema.key_column_usage
where
referenced_table_name is not null;
drop table if exists bookkindlist;
create table bookkindlist
(
bookkindid int not null auto_increment comment '自動增長id',
bookkindname nvarchar(500) not null comment '书类名',
bookkindparent int null comment '父节点',
primary key(bookkindid) #主键
)engine=innodb default charset=utf8 comment='书类表' auto_increment=1;
#更新
delimiter $$
drop procedure if exists `geovindu`.`proc_update_bookkindlist` $$
create procedure `geovindu`.`proc_update_bookkindlist` (in param1id int,in param1name nvarchar(1000),in param1parent int)
begin
if not exists (select * from bookkindlist where bookkindname=param1name) then
update bookkindlist
set
bookkindname=param1name ,
bookkindparent=param1parent
where
bookkindid=param1id;
else
update bookkindlist
set bookkindparent=param1parent
where
bookkindid=param1id;
end if;
end $$
#in 表示输入参数
#out表示输出参数
#inout:表示即可以输入参数也可以输出参数
#存储过程 利用mysql-query-browser创建存储过程和函数
#删除
delimiter $$
drop procedure if exists `geovindu`.`deletebookkind` $$
create procedure `geovindu`.`deletebookkind` (in param1 int)
begin
delete from bookkindlist where bookkindid = param1;
end $$
delimiter ;
#查询所有
delimiter $$
drop procedure if exists `geovindu`.`proc_select_bookkindlistall` $$
create procedure `geovindu`.`proc_select_bookkindlistall` ()
begin
select * from bookkindlist;
end $$
delimiter ;
select * from `geovindu`.`bookkindlist`;
select * from bookkindlist;
#统计
delimiter $$
drop procedure if exists `geovindu`.`bookkindcount` $$
create procedure `geovindu`.`bookkindcount` (out param1id int)
begin
select count(*) into param1id from bookkindlist;
end $$
delimiter ;
#查询一条
delimiter $$
drop procedure if exists `geovindu`.`proc_select_bookkindlist` $$
create procedure `geovindu`.`proc_select_bookkindlist` (in param1 int)
begin
select * from bookkindlist where bookkindid = param1;
end $$
delimiter ;
#插入一条
delimiter $$
drop procedure if exists `geovindu`.`proc_insert_bookkindlist` $$
create procedure `geovindu`.`proc_insert_bookkindlist` (in param1name nvarchar(1000),in param1parent int)
begin
insert into bookkindlist(bookkindname,bookkindparent) values(param1name,param1parent);
end $$
delimiter ;
#插入一条返回值
delimiter $$
drop procedure if exists `geovindu`.`proc_insert_bookkindout` $$
create procedure `geovindu`.`proc_insert_bookkindout` (in param1name nvarchar(1000),in param1parent int,out id int)
begin
if not exists (select * from bookkindlist where bookkindname=param1name) then
insert into bookkindlist (bookkindname,bookkindparent)values(param1name ,param1parent);
#set id=last_insert_id()
select last_insert_id() into id;
end if;
end $$
delimiter ;
/*自定义函数*/
#部门函数
delimiter $$
drop function if exists `geovindu`.`f_getdepartmentname` $$
create function `geovindu`.`f_getdepartmentname` (did int) returns varchar(100)
begin
declare str varchar(100);
return(select departmentname from departmentlist where departmentid=did);
end $$
delimiter ;
#使用函数
select f_getdepartmentname(1);
select * from bookinfolist;
#作家函数
delimiter $$
drop function if exists `geovindu`.`f_getbookkindname` $$
create function `geovindu`.`f_getbookkindname` (did int) returns varchar(400)
begin
declare str varchar(100);
return(select bookkindname from bookkindlist where bookkindid=did);
end $$
delimiter ;
-- 用户浏览记录
drop table if exists duwebstat;
create table if not exists `duwebstat` (
`id` int(11) not null auto_increment comment '自動增長id',
`seepage` varchar(200) character set utf8 null comment '瀏覽的網頁',
`userip` varchar(100) character set utf8 null comment '登錄ip',
`oser` varchar(200) character set utf8 null comment '操作系統',
`operating` varchar(100) character set utf8 null comment '操作系統',
`browser` varchar(500) character set utf8 null comment '瀏覽器',
`visioner` varchar(100) character set utf8 null comment '版本',
`languageer` varchar(100) character set utf8 null comment '語言版本',
`iscookie` varchar(100) character set utf8 null comment '是否有cookie',
`bsize` varchar(100) character set utf8 null comment '瀏覽器尺寸',
`detectedopertor` text character set utf8 null comment '客戶端環境描述',
`addtime` timestamp not null default current_timestamp on update current_timestamp comment '添加時間',
primary key (`id`)
)engine=innodb default charset=utf8 comment='用户浏览记录表' auto_increment=1;
-- 考虑主键外键
--
drop table if exists enterprisetype;
-- 2 企业类型表
create table enterprisetype
(
enterprisetypeid int(20) not null auto_increment comment '自動增長id',
enterprisetypename nvarchar(100) not null comment '企业类型名称', -- 企业类型名称
primary key (enterprisetypeid)
)engine=innodb default charset=utf8 comment='企业类型表' auto_increment=1;
insert into enterprisetype (enterprisetypename) values(n'分公司');
insert into enterprisetype (enterprisetypename) values(n'店铺');
select * from operatinguser;
-- 3 公司表
drop table companybranch;
create table companybranch
(
companyid int(20) not null auto_increment comment '自動增長id',
companyname nvarchar(100) not null comment '公司名称',
companytypeid int not null comment '企业类型id',
companydate timestamp not null default current_timestamp on update current_timestamp comment '添加時間',
companydesc nvarchar(500) null comment '公司描述',
companytel varchar(100) null comment '公司电话',
companyfax varchar(100) null comment '公司传真',
companyaddress nvarchar(500) null comment '公司地址',
primary key (companyid),
foreign key(companytypeid) references enterprisetype(enterprisetypeid)
)engine=innodb default charset=utf8 comment='公司表' auto_increment=1;
insert into companybranch(companyname,companytypeid,companytel,companyfax,companyaddress,companydesc) values('六福珠宝营销策划(深圳)有限公司',1,'','','','');
select * from companybranch;
select * from enterprisetype;
drop table operatinguser;
-- 1
create table operatinguser
(
userid int(20) primary key not null auto_increment comment '自動增長id',
username nvarchar(200) not null comment '用户名', -- 用户名
realname nvarchar(50) not null comment '真实姓名', -- 真姓名
userpassword varchar(100) not null comment '密码', -- 密码
usercompanyid int not null comment '公司id', -- 公司id
userpasswordproblems nvarchar(100) comment '找回密码问题', -- 找回密码问题
usermail varchar(100) null comment '邮件', -- 邮件
userdate timestamp not null default current_timestamp on update current_timestamp comment '添加時間', -- 默认日期
foreign key(usercompanyid) references companybranch(companyid)
)engine=innodb default charset=utf8 comment='用户表' auto_increment=1;
select * from operatinguser;
-- 4 登录日志表
drop table logindiarylist;
drop table if exists logindiarylist;
create table logindiarylist
(
logindiaryid int(20) primary key not null auto_increment comment '自動增長id',
logindiaryusername nvarchar(50) null comment '登錄用戶名', -- 登錄用戶名
logindiaryuserid int not null comment '員工id', -- 員工id
logindiarybrowser varchar(50) null comment '客戶端瀏覽', -- 客戶端瀏覽
logindiaryscreen varchar(50) null comment '显示器大小', -- 显示器大小
logindiaryopertor varchar(50) null comment '操作系統', -- 操作系統
logindiaryinput nvarchar(150) null comment '輸入法', -- 輸入法
logindiarydate timestamp not null default current_timestamp on update current_timestamp comment '添加時間', -- 日期
foreign key(logindiaryuserid) references operatinguser(userid)
)engine=innodb default charset=utf8 comment='登录日志表' auto_increment=1;
select * from logindiarylist;
select * from printworddocumenttemplatelist;
-- 5
drop table if exists printworddocumenttemplatelist;
create table printworddocumenttemplatelist
(
printworddocumentid int primary key auto_increment comment '自動增長id',
-- printworddocumentuid uniqueidentifier default(newid()) primary key,
-- printwordpaytypeuidkey uniqueidentifier, -- 考核類型(試用期,年終,特別)
-- printwordjobtypeuidkey uniqueidentifier, -- -職位類型(文職類,員工類,管理級別類等)
printwordonlypassis bit(1) default b'0' comment '通過試用期並成為正式員工', -- -通過試用期並成為正式員工
printwordplussalaryis bit default b'0' comment '通過並加薪', -- -通過並加薪
printwordpromotionis bit default b'0' comment '通過晉升', -- -通過晉升
printwordextensionis bit default b'0' comment '延長試用期', -- 延長試用期
printworddismissis bit default b'0' comment '解僱', -- 解僱
printworddepartmentis bit default b'0' comment '新部門', -- 新部門
printworddocumentname nvarchar(100) not null comment '文檔標題', -- 文檔標題
printworddocumenturl nvarchar(200) null comment '文檔鏈接', -- 文檔鏈接
printworddocumentcontent nvarchar(300) null comment '文檔簡要描述', -- 文檔簡要描述
printworddocumentadddate timestamp not null default current_timestamp on update current_timestamp comment '添加時間',
printworddocumentbyte blob null comment '文檔',
printwordtype int(20) default 1 comment '文檔類型' -- 文檔類型 1.分公司,2.分店
-- printwordlettersignature nvarchar(100) null -- 信函簽名
)engine=innodb default charset=utf8 comment='打印单表' auto_increment=1;
-- 6
-- 客戶表customer(需方) 名稱,工地名稱
drop table customerlist;
drop table if exists customerlist;
create table customerlist
(
customerid int(20) primary key auto_increment comment '自動增長id',
customername nvarchar(200) not null comment '客户姓名',
customernamepin varchar(500) null comment '拼音首字母',
customercontact nvarchar(50) null comment '聯系人', -- 聯系人
customertel varchar(100) null comment '聯系人電話', -- 聯系人電話
customerdate timestamp not null default current_timestamp on update current_timestamp comment '添加時間'
)engine=innodb default charset=utf8 comment='客戶表' auto_increment=1;
-- 7表單關聯人類型relationshipstype: 指定收貨人 跟單業務員 工地驗收人 運輸人
drop table relationshipstype;
drop table if exists relationshipstype;
create table relationshipstype
(
relationshipstypeid int(20) primary key auto_increment comment '自動增長id',
relationshipstypename nvarchar(100) not null comment '关系类型名称',
relationshipstypepin varchar(500) null comment '拼音首字母'
)engine=innodb default charset=utf8 comment='表單關聯人類型表' auto_increment=1;
insert into relationshipstype(relationshipstypename) values('指定收货人');
insert into relationshipstype(relationshipstypename) values('跟单业务员');
insert into relationshipstype(relationshipstypename) values('工地验收人');
insert into relationshipstype(relationshipstypename) values('运输人');
-- 8表單關係人錶relationshipsperson
drop table relationshipsperson;
drop table if exists relationshipsperson;
create table relationshipsperson
(
personid int(20) primary key auto_increment comment '自動增長id',
personname nvarchar(100) not null comment '姓名',
personnamepin varchar(500) null comment '拼音首字母',
persontel varchar(100) comment '电话',
persontype int not null comment '类型',
persondate timestamp not null default current_timestamp on update current_timestamp comment '添加時間',
foreign key(persontype) references relationshipstype(relationshipstypeid)
)engine=innodb default charset=utf8 comment='表單關係人' auto_increment=1;
select * from relationshipsperson;
-- 9產品名稱表 producttypelist
drop table producttypelist;
drop table if exists producttypelist;
create table producttypelist
(
producttypeid integer primary key auto_increment comment '自動增長id',
producttypename nvarchar(800) not null comment '产品名称',
producttypepin varchar(500) null comment '拼音首字母' -- 字首字母
)engine=innodb default charset=utf8 comment='產品名稱表' auto_increment=1;
-- 10單位表 unitlist comment ''
drop table unitlist;
drop table if exists unitlist;
create table unitlist
(
unitid integer primary key auto_increment comment '自動增長id',
unitname nvarchar(100) not null comment '单位名称',
unitpin varchar(500) null comment '拼音首字母'
)engine=innodb default charset=utf8 comment='單位表' auto_increment=1;
select * from unitlist;
delete from unitlist where unitname='';
drop table productmodel;
-- 产品规格
drop table if exists productmodel;
create table productmodel
(
modelid integer primary key auto_increment comment '自動增長id',
modelproducttypeid int not null comment '产品名称id', -- 产品名称id 外键 producttypelist
modelname nvarchar(800) not null comment '产品规格',
modelpin varchar(500) null comment '拼音首字母',
key modelproducttypeid (modelproducttypeid),
constraint productmodel_ibfk_1 foreign key(modelproducttypeid) references producttypelist(producttypeid)
on update cascade
on delete restrict
)engine=innodb default charset=utf8 comment='产品规格表' auto_increment=1;
-- myisam foreign keys显示不了外键
drop table if exists city;
create table `city` (
`id` int(11) not null auto_increment comment'',
`name` char(35) not null default '' comment'',
`countrycode` char(3) not null default '' comment'',
`district` char(20) not null default '' comment'',
`population` int(11) not null default '0' comment'',
primary key (`id`),
key `countrycode` (`countrycode`),
constraint `city_ibfk_1` foreign key (`countrycode`) references `country` (`code`)
) engine=myisam comment='城市表' auto_increment=4080 default charset=utf8;
drop table if exists country;
create table `country` (
`code` char(3) not null default '' comment'',
`name` char(52) not null default '' comment'',
`continent` enum('asia','europe','north america','africa','oceania','antarctica','south america') not null default 'asia' comment'',
`region` char(26) not null default '' comment'',
`surfacearea` float(10,2) not null default '0.00' comment'',
`indepyear` smallint(6) default null comment'',
`population` int(11) not null default '0' comment'',
`lifeexpectancy` float(3,1) default null comment'',
`gnp` float(10,2) default null comment'',
`gnpold` float(10,2) default null comment'',
`localname` char(45) not null default '' comment'',
`governmentform` char(45) not null default '' comment'',
`headofstate` char(60) default null comment'',
`capital` int(11) default null comment'',
`code2` char(2) not null default '' comment'',
primary key (`code`)
) engine=myisam comment='国家表' default charset=utf8;
-- innodb foreign keys显示外键
drop table if exists city;
create table `city` (
`id` int(11) not null auto_increment comment'',
`name` char(35) not null default '' comment'',
`countrycode` char(3) not null default '' comment'',
`district` char(20) not null default '' comment'',
`population` int(11) not null default '0' comment'',
primary key (`id`),
key `countrycode` (`countrycode`),
constraint `city_ibfk_1` foreign key (`countrycode`) references `country` (`code`)
) engine=innodb comment='城市表' auto_increment=4080 default charset=utf8;
drop table if exists country;
create table `country` (
`code` char(3) not null default '' comment'',
`name` char(52) not null default '' comment'',
`continent` enum('asia','europe','north america','africa','oceania','antarctica','south america') not null default 'asia' comment'',
`region` char(26) not null default '' comment'',
`surfacearea` float(10,2) not null default '0.00' comment'',
`indepyear` smallint(6) default null comment'',
`population` int(11) not null default '0' comment'',
`lifeexpectancy` float(3,1) default null comment'',
`gnp` float(10,2) default null comment'',
`gnpold` float(10,2) default null comment'',
`localname` char(45) not null default '' comment'',
`governmentform` char(45) not null default '' comment'',
`headofstate` char(60) default null comment'',
`capital` int(11) default null comment'',
`code2` char(2) not null default '' comment'',
primary key (`code`)
) engine=innodb comment='国家表' default charset=utf8;
drop table unitprice;
-- 单价表
drop table if exists unitprice;
create table unitprice
(
unitpriceid integer primary key auto_increment comment '自動增長id',
unitproducttypeid int not null comment '产品名称id', -- 产品名称id 外键 producttypelist
unitpricenuber decimal(20,2) not null comment '单价',
unitpricepin varchar(500) null comment '拼音首字母',
foreign key(unitproducttypeid) references producttypelist(producttypeid)
on update cascade
on delete restrict
)engine=innodb default charset=utf8 comment='单价表' auto_increment=1;
select * from unitprice;
drop table customeraddress;
-- 客户地址表
drop table if exists customeraddress;
create table customeraddress
(
addressid integer primary key auto_increment comment '自動增長id',
addressname nvarchar(100) not null comment '地名',
addresspin varchar(500) null comment '拼音首字母'
)engine=innodb default charset=utf8 comment='客户地址表' auto_increment=1;
-- 11級別表 levellist
drop table levellist;
drop table if exists levellist;
create table levellist
(
levelid integer primary key auto_increment comment '自動增長id',
levelname nvarchar(100) not null comment '级别名称',
levelpin varchar(500) null comment '拼音首字母'
)engine=innodb default charset=utf8 comment='級別表' auto_increment=1;
select * from levellist;
delete from levellist where levelname='';
-- 12工地名名稱表 建筑工地名construction site name
drop table constructionnamelist;
drop table if exists constructionnamelist;
create table constructionnamelist
(
constructionid integer primary key auto_increment comment '自動增長id',
constructionname varchar(100) not null comment '工地名称',
constructionpin varchar(500) null comment '拼音首字母'
)engine=innodb default charset=utf8 comment='工地名名稱表' auto_increment=1;
select * from constructionnamelist;
delete from constructionnamelist where constructionname='';
-- 訂單產品詳情表
drop table orderitdetails;
drop table if exists orderitdetails;
create table orderitdetails
(
orderid integer primary key auto_increment comment '自動增長id',
orderdate timestamp not null default current_timestamp on update current_timestamp comment '送货日期', -- 送货日期
orderword varchar(50) null comment '字', -- 字
orderno varchar(100) null comment '号', -- 号
ordercustomerid int not null comment '客户名稱', -- 客户名稱
orderaddressid int not null comment '客户地址名稱', -- 客户地址名稱
orderprepared int null comment '製單人', -- 製單人
orderbusiness int null comment '指定收货人', -- 指定收货人
orderprintdate timestamp not null default current_timestamp on update current_timestamp comment '打單時間', -- 打單時間
foreign key(ordercustomerid) references customerlist(customerid)
on update cascade
on delete restrict,
foreign key(orderaddressid) references customeraddress(addressid)
on update cascade
on delete restrict,
foreign key(orderprepared) references relationshipsperson(personid)
on update cascade
on delete restrict,
foreign key(orderbusiness) references relationshipsperson(personid)
on update cascade
on delete restrict
)engine=innodb default charset=utf8 comment='訂單產品詳情表' auto_increment=1;
-- 訂單產品詳情
drop table productitorderdetails;
drop table if exists productitorderdetails;
create table productitorderdetails
(
productdetailsid integer primary key auto_increment comment '自動增長id',
productorderid int not null comment '產品訂單id', -- 產品訂單id 外錶orderdetails
productordertypeid int not null comment '產品名稱id', -- 產品名稱
productmodleid int comment '規格id', -- 規格
productunitid int comment '單位id', -- 單位
productqty decimal(18,2) default 0 comment '數量', -- 數量
productpriceid int not null comment '单价id', -- 单价
productmeters decimal(25,2) default 0 comment '金额', -- 金额
productdescription varchar(1000) null comment '說明', -- 說明
foreign key(productorderid) references orderitdetails(orderid)
on update cascade
on delete restrict,
foreign key(productordertypeid) references producttypelist(producttypeid)
on update cascade
on delete restrict,
foreign key(productmodleid) references productmodel(modelid)
on update cascade
on delete restrict,
foreign key(productunitid) references unitlist(unitid)
on update cascade
on delete restrict,
foreign key(productpriceid) references unitprice(unitpriceid)
on update cascade
on delete restrict
)engine=innodb default charset=utf8 comment='訂單產品詳情表' auto_increment=1;
-- 13打單表內容 productdetails
-- https://www.sqlite.org/datatype3.html
drop table orderdetails;
drop table if exists orderdetails;
create table orderdetails
(
orderid integer primary key auto_increment comment '自動增長id',
orderdate timestamp not null default current_timestamp on update current_timestamp comment '添加時間', -- 日期
orderword nvarchar(50) null comment '字', -- 字
orderno nvarchar(100) null comment '号', -- 号
ordercustomerid int not null comment '需求方id', -- 需求方
orderconstructionid int not null comment '工地名稱id', -- 工地名稱
-- orderproductid int not null, -- 產品訂單詳情id 外錶productorderdetails
orderacceptor int null comment '工地驗收人id', -- 工地驗收人
ordertransportation integer null comment '運輸人id', -- 運輸人
orderprepared int null comment '製單人id', -- 製單人
orderbusiness int null comment '指定業務人id', -- 指定業務人
ordermerchandiser int null comment '跟單業務員id', -- 跟單業務員
orderprintdate timestamp not null default current_timestamp on update current_timestamp comment '打單時間',-- 打單時間
foreign key(ordercustomerid) references customerlist(customerid)
on update cascade
on delete restrict,
foreign key(orderconstructionid) references constructionnamelist(constructionid)
on update cascade
on delete restrict,
foreign key(orderacceptor) references relationshipsperson(personid)
on update cascade
on delete restrict,
foreign key(ordertransportation) references relationshipsperson(personid)
on update cascade
on delete restrict,
foreign key(orderprepared) references relationshipsperson(personid)
on update cascade
on delete restrict,
foreign key(orderbusiness) references relationshipsperson(personid)
on update cascade
on delete restrict,
foreign key(ordermerchandiser) references relationshipsperson(personid)
on update cascade
on delete restrict
)engine=innodb default charset=utf8 comment='打單表內容表' auto_increment=1;
-- 14訂單產品詳情表 numeric
drop table productorderdetails;
drop table if exists productorderdetails;
create table productorderdetails
(
productdetailsid int primary key auto_increment comment '自動增長id',
productorderid int not null comment '產品訂單id', -- 產品訂單id 外錶orderdetails
producttypeid int not null comment '產品名稱規格id', -- 產品名稱規格
productunitid int not null comment '單位id', -- 單位
productqty decimal(18,2) default 0.0 comment '數量', -- 數量
productlevelid int not null comment '級別id', -- 級別
productmeters decimal(25,2) default 0 comment '米數', -- 米數
productdescription nvarchar(1000) null comment '說明', -- 說明
foreign key(productorderid) references orderdetails(orderid)
on update cascade
on delete restrict,
foreign key(producttypeid) references producttypelist(producttypeid)
on update cascade
on delete restrict,
foreign key(productunitid) references unitlist(unitid)
on update cascade
on delete restrict,
foreign key(productlevelid) references levellist(levelid)
on update cascade
on delete restrict
)engine=innodb default charset=utf8 comment='訂單產品詳情表' auto_increment=1;
-- 設置移動打印x,y坐標糾正值
drop table printsetnumber;
drop table if exists printsetnumber;
create table printsetnumber
(
printsetid int primary key auto_increment comment '自動增長id',
printsetx int unsigned default 0 comment '列坐标', -- com 列坐标
printsety int default 0 comment '行坐标', -- row 行坐标
printprinter varchar(200) null comment '默认打印机名', -- 默认打印机名
printfont varchar(200) null default '宋体' comment '默认字体名',-- 默认字体名
printbottom bit default 0 comment '底部文字是否双排', -- 底部文字是否双排
titlefontsize int default 8 comment '标题字体大小', -- 标题字体大小
confontsize int default 8 comment '内容字体大小', -- 内容字体大小
headfontsize int default 8 comment '表头字体大小', -- 表头字体大小
boomfontsize int default 8 comment '表底字体大小' -- 表底字体大小
)engine=innodb default charset=utf8 comment='設置移動打印' auto_increment=1;
-- 表的描述
drop table datatabledesc;
drop table if exists datatabledesc;
create table datatabledesc
(
tableid int primary key auto_increment comment '自動增長id',
tablename nvarchar(100) not null comment '表名',
tabledesc nvarchar(100) null comment '表描述'
)engine=innodb default charset=utf8 comment='表的描述' auto_increment=1;
-- 列的列描述 columnname
drop table datacolumndesc;
drop table if exists datacolumndesc;
create table datacolumndesc
(
columnid int primary key auto_increment comment '自動增長id',
columntableid int not null comment '表id',
columnname nvarchar(100) not null comment '列名',
columndesc nvarchar(100) null comment '列描述',
-- key columntableid (columntableid), --此项添上也可以
-- constraint `datacolumndesc_ibfk_1` --此项添上也可以
foreign key(columntableid) references datatabledesc(tableid)
)engine=innodb default charset=utf8 comment='列的列描述' auto_increment=1;
select * from datatabledesc;
select * from datacolumndesc;
select * from printsetnumber;
-- 视图
create view v_datatablecolumn as
select datacolumndesc.*,datatabledesc.tablename,datatabledesc.tabledesc from datacolumndesc,datatabledesc
where datatabledesc.tableid=datacolumndesc.columntableid;
create view v_operatinguser as
select operatinguser.*,companybranch.companyname,companybranch.companytel,companybranch.companyfax,companybranch.companyaddress
from operatinguser,companybranch where operatinguser.usercompanyid=companybranch.companyid;
drop view v_companybranch;
-- 公司
create view v_companybranch
as
select companybranch.*,enterprisetype.enterprisetypename from companybranch, enterprisetype where companybranch.companytypeid=enterprisetype.enterprisetypeid;
select companybranch.*,enterprisetype.enterprisetypename from companybranch, enterprisetype where companybranch.companytypeid=enterprisetype.enterprisetypeid;
select * from v_companybranch;
drop view v_operatinguser;
-- 用户
create view v_operatinguser
as
select operatinguser.*,companybranch.companyname,companybranch.companytel,companybranch.companyfax,companybranch.companyaddress from operatinguser,companybranch where operatinguser.usercompanyid=companybranch.companyid;
select * from v_operatinguser;
-- 錶單用戶視圖
create view view_relationshipsperson
as
select relationshipsperson.*,relationshipstype.relationshipstypename from relationshipsperson,relationshipstype
where relationshipsperson.persontype=relationshipstype.relationshipstypeid;
-- 订单视图
using system;
using system.collections.generic;
using system.componentmodel;
using system.data;
using system.drawing;
using system.linq;
using system.text;
using system.windows.forms;
using system.configuration;
using mysql.data;
using mysql.data.mysqlclient;
/*
*
metadatacollections
datasourceinformation
datatypes
restrictions
reservedwords
databases
tables
columns
users
foreign keys
indexcolumns
indexes
foreign key columns
udf
views
viewcolumns
procedure parameters
procedures
triggers
*/
namespace mysqldemo
{
/// <summary>
///
/// </summary>
public partial class form2 : form
{
/// <summary>
/// 都可以用
/// </summary>
private static string connectionstring = @"database='geovindu';data source='localhost';user id='root';password='88888';charset='utf8';pooling=true;port=3306;allow zero datetime=true;";
/// <summary>
/// 都可以用
/// </summary>
private static string connectionstring1 = @"database='geovindu';server='localhost';user id='root';password='88888';charset='utf8';pooling=true;port=3306;allow zero datetime=true;";
/// <summary>
///
/// </summary>
/// <returns></returns>
private datatable settables()
{
datatable dt = new datatable();
dt.columns.add("id", typeof(int));
dt.columns.add("name", typeof(string));
dt.rows.add(1, "metadatacollections");//metadata集合
dt.rows.add(2, "datasourceinformation");//数据库文件版本等信息
dt.rows.add(3, "datatypes");//字段类型
dt.rows.add(4, "restrictions");//架构限制
dt.rows.add(5, "reservedwords");//限制关键字
dt.rows.add(6, "databases");//数据库(包含系统数据库)
dt.rows.add(7, "tables");//所有表包括系统表
dt.rows.add(8, "columns");//表的字段
dt.rows.add(9, "users");//用户
dt.rows.add(10, "foreign keys");//外键表和主表 (不包含列)
dt.rows.add(11, "indexcolumns");//有键的表及主键
dt.rows.add(12, "indexes");//所有有主键的表
dt.rows.add(13, "foreign key columns");// 外键表和主表及列
dt.rows.add(14, "udf");//
dt.rows.add(15, "views");//所有视图
dt.rows.add(16, "viewcolumns");//视图的字段
dt.rows.add(17, "procedure parameters");//存储过程参数
dt.rows.add(18, "procedures");//存储过程
dt.rows.add(19, "triggers");
return dt;
}
/// <summary>
///
/// </summary>
mysqlconnection connection = new mysqlconnection(connectionstring1);
/// <summary>
/// open connection to database
/// </summary>
/// <returns></returns>
private bool openconnection()
{
try
{
connection.open();
return true;
}
catch (mysqlexception ex)
{
//when handling errors, you can your application's response based
//on the error number.
//the two most common error numbers when connecting are as follows:
//0: cannot connect to server.
//1045: invalid user name and/or password.
switch (ex.number)
{
case 0:
messagebox.show("cannot connect to server. contact administrator");
break;
case 1045:
messagebox.show("invalid username/password, please try again");
break;
}
return false;
}
}
/// <summary>
/// close connection
/// </summary>
/// <returns></returns>
private bool closeconnection()
{
try
{
connection.close();
return true;
}
catch (mysqlexception ex)
{
messagebox.show(ex.message);
return false;
}
}
/// <summary>
///
/// </summary>
public form2()
{
initializecomponent();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void form2_load(object sender, eventargs e)
{
this.combobox1.datasource = settables();
this.combobox1.displaymember = "name";
this.combobox1.valuemember = "id";
//connection.open();
//this.datagridview1.datasource = connection.getschema();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_click(object sender, eventargs e)
{
connection.open();
this.datagridview1.datasource = connection.getschema(this.combobox1.text);
connection.close();
}
}
}
上一篇: 山药的药用价值是什么,它有什么药用价值
下一篇: 【第七章】MySQL数据库备份-物理备份
推荐阅读
-
MySQL5.7: sql script demo
-
MySQL5.7 sql_mode=only_full_group_by的解决办法
-
SQL Server: create table sql script
-
MySQL5.7中的sql_mode默认值带来的坑及解决方法
-
MYSQL5.7版本sql_mode=only_full_group_by问题,重启有效的方法
-
mysql5.7 gruop by报错this is incompatible with sql_mode=only_full_group_by
-
SQL性能优化之定位网络性能问题的方法(DEMO)
-
使用go实现删除sql里面的注释和字符串功能(demo)
-
可重复执行的SQL Script
-
ApexSQL Log中的Redo Script跟原始SQL不一致问题