成都網(wǎng)絡(luò)公司-成都網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)十余年經(jīng)驗(yàn)成就非凡,專業(yè)從事成都網(wǎng)站建設(shè)、成都做網(wǎng)站,成都網(wǎng)頁設(shè)計(jì),成都網(wǎng)頁制作,軟文平臺(tái),一元廣告等。十余年來已成功提供全面的成都網(wǎng)站建設(shè)方案,打造行業(yè)特色的成都網(wǎng)站建設(shè)案例,建站熱線:18980820575,我們期待您的來電!

1,navicat外鍵怎么設(shè)置
打開我的navicat,然后找到我的teacher表,選中它,然后點(diǎn)擊菜單欄上 在彈出的對話框中找到“Foreign Keys”,然后單機(jī)。2,SQL如何設(shè)置外鍵
可以在創(chuàng)建表的時(shí)候創(chuàng)建,也可以在創(chuàng)建表之后創(chuàng)建。創(chuàng)建表時(shí)創(chuàng)建:create table student(id int primary key,name char(4),dept char(9)sex char(4))create table grade(id int ,grade intconstraint id_fk foreign key (id) references student (id))或創(chuàng)建了兩表之后再建alter table gradeadd constraint id_fk foreign key (id) references student (id)呵呵,希望能幫助你。首先在booktype表中定義主鍵:booktypeidcreate table booktype (booktypeid varchar(20) primary key,typename varchar(20));create table book (bookid int primary key, bookname varchar(20),booktypeid varchar(20) ,constraint fk foreign key(booktypeid) references booktype(booktypeid));3,如何設(shè)置外鍵約束
create table t1(A1 int primary key)create table t2(B1 int,B2 int)--對t2表的B2創(chuàng)建外鍵alter table t2 add constraint FK_B2_t1A1 foreign key(B2) references t1(A1)--注意:能作為一個(gè)表的外鍵關(guān)聯(lián)字段(t1.A1)這個(gè)字段必須是主鍵或有唯一約束的(t1的A1必須是主鍵或者unique)create table t1(A1 int primary key)create table t2(B1 int,B2 int)--對t2表的B2創(chuàng)建外鍵(關(guān)聯(lián)字段t1表的A1字段)alter table t2 add constraint FK_B2_t1A1 foreign key(B2) references t1(A1)--注意:能作為一個(gè)表的外鍵關(guān)聯(lián)字段(t1.A1)這個(gè)字段必須是主鍵或有唯一約束的(t1的A1必須是主鍵或者unique)create table a ( a_id int primary key, ##主鍵 a_name varchar(2))create table b( b_id int , b_name varchar(2))##添加外鍵alter table b add constraint fk_b_a foreign key b_id references a(a_id)4,怎么給聯(lián)合主鍵設(shè)置外鍵啊
GUI界面,先右鍵表B,表C,選擇設(shè)計(jì),然后選擇表B字段b1設(shè)置主鍵,表C字段c1設(shè)置主鍵,然后保存關(guān)閉。右鍵表A,選擇設(shè)計(jì),按住shift然后選擇a1,a2設(shè)置為聯(lián)合主鍵,然后右鍵a1列,選擇關(guān)系,添加后右面點(diǎn)擊表和列規(guī)范,彈出界面,左邊選擇主鍵表主鍵列,右面選擇本表字段a1即可。a2同樣設(shè)置。語句的我知道用references就行 可是可視化的操作可以做到么?我正好有一個(gè)例子和你說的一樣,請參考:CREATE TABLE [dbo].[ContractorMobileService]( [ContractorID] [int] NOT NULL, [MobileServiceID] [int] NOT NULL, [Charge] [money] NOT NULL, CONSTRAINT [PK_ContractorMobileService] PRIMARY KEY CLUSTERED ( [ContractorID] ASC, [MobileServiceID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]GOALTER TABLE [dbo].[ContractorMobileService] WITH NOCHECK ADD CONSTRAINT [FK_ContractorMobileService_Contractor] FOREIGN KEY([ContractorID])REFERENCES [dbo].[Contractor] ([ID])GOALTER TABLE [dbo].[ContractorMobileService] CHECK CONSTRAINT [FK_ContractorMobileService_Contractor]GOALTER TABLE [dbo].[ContractorMobileService] WITH NOCHECK ADD CONSTRAINT [FK_ContractorMobileService_MobileService] FOREIGN KEY([MobileServiceID])REFERENCES [dbo].[MobileService] ([ID])GOALTER TABLE [dbo].[ContractorMobileService] CHECK CONSTRAINT [FK_ContractorMobileService_MobileService]GO
5,如何創(chuàng)建外鍵是本身表的主鍵的外鍵
create table NewsType(id INT PRIMARY KEY ,parentId int references NewsType(id))其他字段你自己添吧 比如插入測試數(shù)據(jù)insert into NewsType values (1,1);--這個(gè)執(zhí)行沒問題insert into NewsType values (2,3);--會(huì)報(bào)錯(cuò)可以用數(shù)據(jù)庫工具創(chuàng)建。具體方法如下:create table TabA (AF1 string ,AF2 int null,AF3 int null)create table TabB (BF1 string ,BF2 int )//創(chuàng)建constraint PK_AF1 primary key (AF1)constraint TabB primary key (BF1),constraint FK_Tab1_TAB2 foreign key (BF2)references TabA(AF1)具體例子如下:create table VAS_POSSTOR_DETAIL ( TEAMNO VARCHAR2(10) not null, POS_NO VARCHAR2(3) not null, ITEM_CODE VARCHAR2(10) not null, SORT_NO VARCHAR2(5) not null, INIT_QUANTITY NUMBER, STO_QUANTITY NUMBER, ORD_QUANTITY NUMBER, DEL_PRICE NUMBER(10,4), constraint PK_VAS_POSSTOR_DETAIL primary key (TEAMNO, POS_NO, ITEM_CODE), constraint FK_VAS_POSS_REFERENCE_VAS_POS foreign key (TEAMNO, POS_NO) references VAS_POSSTORAGE (TEAMNO, POS_NO)??創(chuàng)建表的語法-創(chuàng)建表格語法:create table 表名(???? 字段名1?? 字段類型(長度) 是否為空,???? 字段名2?? 字段類型???????????? 是否為空);-增加主鍵alter table 表名 add constraint 主鍵名 primary key (字段名1);-增加外鍵:alter table 表名???? add constraint 外鍵名 foreign key (字段名1)?????????? references 關(guān)聯(lián)表 (字段名2);在建立表格時(shí)就指定主鍵和外鍵create table t_stu?? (
分享名稱:外鍵怎么設(shè)置,navicat外鍵怎么設(shè)置
當(dāng)前地址:http://chinadenli.net/article16/icjpdg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、關(guān)鍵詞優(yōu)化、靜態(tài)網(wǎng)站、軟件開發(fā)、網(wǎng)站排名、網(wǎng)站導(dǎo)航
廣告
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源:
創(chuàng)新互聯(lián)