mysql外賣怎么寫,外賣內(nèi)容怎么寫

mysql的sql語句怎么寫?

這個是SQL SERVER的語法,MY SQL的思路應(yīng)該是類似的

創(chuàng)新互聯(lián)建站是一家專注于網(wǎng)站設(shè)計、成都網(wǎng)站設(shè)計與策劃設(shè)計,昂仁網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)建站做網(wǎng)站,專注于網(wǎng)站建設(shè)10余年,網(wǎng)設(shè)計領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:昂仁等地區(qū)。昂仁做網(wǎng)站價格咨詢:18982081108

---------------------------------------------------------

select

*

from

(select

isnull(sum(online_count),0) h16

from

#a

where

datepart(hh,watch_time)=16) a,

(select

isnull(sum(online_count),0) h17

from

#a

where

datepart(hh,watch_time)=17) b,

(select

isnull(sum(online_count),0) h18

from

#a

where

datepart(hh,watch_time)=18) c,

(select

isnull(sum(online_count),0) h19

from

#a

where

datepart(hh,watch_time)=19) d

怎么寫一個MySQL自動執(zhí)行腳本

呵呵~前幾天剛搞好這個...

分兩個BAT(1.bat,2.bat)~~當(dāng)然可以連起來~BAT路徑自己修改

1.bat內(nèi)容以下

D:\wamp\bin\mysql\mysql5.5.8\bin\mysql -uroot -p D:\wamp\www\mysqlCreatDB.sql

2.bat

mysqlCreatDB.sql內(nèi)容為:create database “自己數(shù)據(jù)庫名字”

2.bat內(nèi)容以下

@ECHO off

set user=root

set pass=

set wdb=gx

set port=3306

set server=localhost

@ECHO 正在安裝數(shù)據(jù)庫....

D:\wamp\bin\mysql\mysql5.5.8\bin\mysql -h %server% --user=%user% --password=%pass% --port=%port% %wdb% D:\wamp\www\自己導(dǎo)出的SQL文件

@ECHO 安裝完畢

mysql外鍵約束怎么寫

你好朋友

1.簡介

外鍵表示一個表中的一個字段被另外一個表中的字段應(yīng)用.外鍵對相關(guān)表中的數(shù)據(jù)造成了限制,使MySQL 能夠保證參照完整性.

在MySQL 中,InnoDB 存儲引擎支持外鍵.在一張表中,可以存在多個外鍵.

外鍵的創(chuàng)建可以在創(chuàng)建表的時候創(chuàng)建,也可以在創(chuàng)建表之后增加(考慮數(shù)據(jù)的完整性問題).

父表:外鍵所指向的表.

字表:相對于父表,擁有外鍵的表.

2.語法

create 語法

create table table_name(

column_1,

column_2,

....

constraint constraint_name foreign key (column_name)

references parent_table(column_name)

on delete action

on update action

) engine=InnoDB default charset utf8;

constraint 子句允許為外鍵定義一個名稱,如果不寫,MySQL 自動生成一個名稱

foreign key 子句指定子表中要應(yīng)用父表的列.注意:MySQL 會自動創(chuàng)建一個基于外鍵的索引.

references 子句指定父表中的被引用字段.foreign key 和references 指定的列數(shù)必須相同.

on delete: 定義當(dāng)父表中的記錄被刪除時,子表的記錄應(yīng)該執(zhí)行的動作.action包括:

on delete restrict:(默認(rèn)),父表不能刪除一個已經(jīng)被子表引用的記錄.

on delete no action:等同與on delete restrict

on delete cascade: 級聯(lián)模式,父表刪除后,對應(yīng)子表關(guān)聯(lián)的數(shù)據(jù)也跟著被刪除

on delete set null:置空模式,父表刪除后,對應(yīng)子表關(guān)聯(lián)的外鍵值被設(shè)置為NULL,需要注意的是,如果子表的外鍵設(shè)置not null ,則不能使用這種模式,因?yàn)闀嗷_突.

on update:定義父表中的記錄更新時,子表的記錄應(yīng)該執(zhí)行的動作.action 包括:

on update restrict:(默認(rèn)),父表不能更新一個已經(jīng)被子表引用的記錄.

on update no action:等同與on delete restrict

on update cascade: 級聯(lián)模式,父表更新后,對應(yīng)子表關(guān)聯(lián)的數(shù)據(jù)也跟著被更新

on update set null:置空模式,父表更新后,對應(yīng)子表關(guān)聯(lián)的外鍵值被設(shè)置為NULL,需要注意的是,如果子表的外鍵設(shè)置not null ,則不能使用這種模式.

alter 語法

-- 添加外鍵

alter table table_name add constraint constraint_name

foreign key column_name

references parent_table(column_name)

on delete action

on update action

-- 刪除外鍵

alter table table_name drop constraint_name;

-- 如果沒有顯式的定義名字,可以使用如下命令獲取

show create table table_name;

3.演示

構(gòu)造兩張表categoryes 和products.每個類別有多種產(chǎn)品,而每個產(chǎn)品只屬于一個類別.

-- 設(shè)置 類別表 categoryes 和產(chǎn)品表 products

create table categoryes(

c_id int not null auto_increment,

c_name varchar(45) not null,

c_description text,

primary key (c_id)

) engine=InnoDB default charset utf8 comment '類別表';

create table products(

p_id int not null auto_increment,

p_name varchar(45) not null,

p_price decimal(8,4),

c_id int,

primary key (p_id),

constraint fk_products_categoryes

foreign key (c_id)

references categoryes(c_id)

on delete set null

on update cascade

) engine=InnoDB default charset utf8 comment '產(chǎn)品表';

在這兩張表的基礎(chǔ)上,新生成一張vendors 供應(yīng)商表,并更新products字段

-- 新生成一張表 供應(yīng)商 vendors ,并為 products 新添加字段 v_id 外鍵

-- 引用 vendors.v_id

create table vendors(

v_id int not null auto_increment,

v_name varchar(45),

primary key (v_id)

) engine=InnoDB default charset utf8 comment '供應(yīng)商';

alter table products add column v_id int not null;

alter table products add

constraint fk_products_vendors foreign key (v_id)

references vendors(v_id)

on delete no action

on update cascade;

望采納祝你好運(yùn)

網(wǎng)頁名稱:mysql外賣怎么寫,外賣內(nèi)容怎么寫
文章URL:http://muchs.cn/article28/phijcp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站網(wǎng)站導(dǎo)航、定制開發(fā)網(wǎng)站排名、App開發(fā)、電子商務(wù)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化