--books表中有字段有bId,pId等字段。
創(chuàng)新互聯(lián)公司成立與2013年,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目成都網(wǎng)站設(shè)計、網(wǎng)站制作網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元且末做網(wǎng)站,已為上家服務(wù),為且末各地企業(yè)和個人服務(wù),聯(lián)系電話:13518219792
--another有bId,pId等字段(create table another select bId,pid,bAuthor from books;--相關(guān)字段以及內(nèi)容來自books表)。
--books和publising建立外鍵,參照publishing中的id字段。
alter table books add constraint FK_books_publishing foreign key (pid) references publishing (id) on update cascade;
--another和publishing之間創(chuàng)建外鍵,參照publishing中的id字段。
alter table another add constraint FK_another_publishing foreign key (pId) references publishing (id) on update cascade;
--舉個簡單的更新列子:
update publishing set id = 17,pname = '愛好者' where id='14';
--當(dāng)執(zhí)行這條語句時(更新publishing表),books表和another表同時進(jìn)行更新。
--主表更新字段數(shù)據(jù)等,副表也隨之更新,從上面可以看出,主表是publishing,副表是books和another。
--希望能幫到你
select a.name, max(b.log_time) from 表1 as a, 表2 as b where a.id = b.user_id group by a.name 根據(jù)您最新的需求,SQL修改如下,保證查詢效率沒的說: select a.id, a.name, max(b.log_time), ( select c.content from 表2 as c where c.us..
這個主要看需求。
你主要要獲取那個表的數(shù)據(jù),一般應(yīng)該作為主表
另一個表的數(shù)據(jù)如果關(guān)聯(lián)不上的話,獲取列是以null表示的。
主表
在數(shù)據(jù)庫中建立的表格即Table,其中存在主鍵(primary key)用于與其它表相關(guān)聯(lián),并且作為在主表中的唯一性標(biāo)識。
從表
以主表的主鍵(primary key)值為外鍵 (Foreign Key)的表,可以通過外鍵與主表進(jìn)行關(guān)聯(lián)查詢。從表與主表通過外鍵進(jìn)行關(guān)聯(lián)查詢。
關(guān)系及用法概述
從表數(shù)據(jù)依賴于主表,一般最后查詢數(shù)據(jù)時把主表與從表進(jìn)行關(guān)聯(lián)查詢。主表可用于存儲主要信息,如客戶資料(客戶編號,客戶名稱,客戶公司,客戶單位等),從表用來存儲客戶擴(kuò)展信息(客戶訂單信息,客戶地址信息,客戶聯(lián)系方式信息等)
簡單舉例:
主表(用戶信息)
table user
userid numeric(0,20)
username varchar2(20)
usercompany varchar2(50)
從表(用戶訂單)
table uorder
orderid numeric(0,20)
uid numeric(0,20)
ordertime date
orderstate char(1)
要對主表和從表進(jìn)行信息聯(lián)合查詢語句簡單如下:
select * from [user] u join uorder o on u.userid=o.uid
網(wǎng)頁標(biāo)題:mysql主表怎么確定 mysql怎么看主從
地址分享:http://www.rwnh.cn/article34/ddihhpe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、面包屑導(dǎo)航、微信公眾號、品牌網(wǎng)站建設(shè)、網(wǎng)站內(nèi)鏈、網(wǎng)站改版
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)