mysql主从配置cobf_不能在mysql中創建表,因為它們都相互依賴?

I have one table Supplier that has foreign key RepID, and another called Rep that has foreign key SupplierID. How do I get around this? If I disable foreign key checking I get an error saying a foreign key constraint fails when trying to add data:

我有一個具有外鍵RepID的表供應商,另一個名為具有外鍵供應商ID的代表。我該如何解決這個問題?如果我禁用外鍵檢查,我會在嘗試添加數據時收到錯誤,指出外鍵約束失敗:

INSERT INTO Supplier VALUES

(44, "PENCO", "43", "Brown road", "Penville", "P14 5AA", "07816272182"),

(13, "PAPERCO", "1", "Old road", "Paperville", "P34 5NA", "07111232289"),

(24, "CALCCO", "12", "London road", "Calcville", "CA4 1XX", "07615282615"),

(8, "BAGCO", "10", "New road", "Bagville", "BA1 1AM", "07817827131");

INSERT INTO Item VALUES

(1, "Ballpoint pen", 1.00, "A nice pen", "~/Pictures/Pen", 20, 44),

(2, "Notepad", 3.20, "A nice notepad", "~/Pictures/Notepad", 21, 13),

(3, "Calculator", 4.50, "A nice calculator", "~/Pictures/Calculator", 22, 24),

(4, "Backpack", 10.00, "A nice backpack", "~/Pictures/Backpack", 23, 8);

INSERT INTO Rep VALUES

(41, "John", "Repman", "07019827336", 44, "JR@gmail.com", "JR@msn.com", "JRMAN", "1", "Potato street", "Patatoville", "P01 1FX"),

(11, "Fake", "Name", "07817001992", 13, "FN@gmail.com", "FN@msn.com", "FNMAN", "3", "Fake street", "Fakeville", "FA3 9KA"),

(1, "Good", "Name", "07911876678", 24, "GN@gmail.com", "GN@msn.com", "GNMAN", "12", "Good street", "Goodville", "GO0 1DD"),

(666, "John", "Smith", "07918822191", 8, "JS@gmail.com", "JS@msn.com", "JSMAN", "666", "Boring street", "Boringville", "BO1 1LM");

2 个解决方案

#1

0

You can disable the foregin key check with this:

您可以使用以下命令禁用foregin密鑰檢查:

SET foreign_key_checks = 0;

CREATE TABLES ......;

SET foreign_key_checks = 1;

#2

0

Add the first table without foreign keys, then the second with all keys, then create the foreign key on the first table.

添加沒有外鍵的第一個表,然后添加第二個包含所有鍵,然后在第一個表上創建外鍵。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值