这是一个医疗商店数据库的示例,它以“ python”编码。我有两个表,第一个是Store,另一个是Staff。我先将数据插入到商店中,然后当我尝试将数据插入到商店中时第二个表(Staff),它给出一个错误,指出子行无法更新,这是代码:
mycursor.execute("""CREATE TABLE Store
(StoreId INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
Phone BIGINT NOT NULL,
City VARCHAR(20) NOT NULL,
Postal_Code VARCHAR(10) NOT NULL)""")
mycursor.execute("""CREATE TABLE Staff
(StaffId INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
StoreId INT NOT NULL,
foreign key (StoreId) REFERENCES Store(StoreId),
First_Name VARCHAR(10) NOT NULL,
Last_Name VARCHAR(10) NOT NULL,
Email VARCHAR(30) NOT NULL,
JobTitle VARCHAR(20) NOT NULL)""")
mycursor.execute("""INSERT INTO Staff (First_Name, Last_Name, Email, JobTitle) VALUES
('usama', 'imtiaz','osama_imtiaz677@yahoo.com','cashier'),
('taha', 'Nadeem','taha_nadeem@yahoo.com','Computer operator'),
('Fahad', 'Awan','Fahadawan@gmail.com','supervisor'),
('Ahsan', 'Shafiq', 'Ahsan_shafiq12@hotmail.com','manager'),
('Nimra', 'Islam','Nimraislam261@gmail.com','General Manager')""")