Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > MySQL
|
MySQL General discussion about the MySQL database.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the MySQL section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 8th, 2004, 09:56 AM
Authorized User
 
Join Date: Jan 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Try this and tell me whats the problem?

CREATE TABLE publisher (
     publisherID int(11) NOT NULL auto_increment,
     publisherName varchar(32) NOT NULL default '',
     PRIMARY KEY(publisherID)
   ) TYPE=INNODB;


--
-- Table structure for table 'authors'
--
CREATE TABLE authors (
     authorID int(11) NOT NULL auto_increment,
     FirstName varchar(20) NOT NULL default '',
     LastName varchar(20) NOT NULL default '',
     PRIMARY KEY (authorID)
   ) TYPE=INNODB;




--
-- Table structure for table 'titles'
--
CREATE TABLE titles (
     isbn varchar(20) NOT NULL,
     title varchar(64) NOT NULL,
     copyright varchar(20) NOT NULL,
     publisherID int(11) NOT NULL,
     comments varchar(128) NOT NULL default '',
     publishers_publisherID INT,
     PRIMARY KEY(isbn),
     INDEX (publishers_publisherID),
     FOREIGN KEY(publishers_publisherID) REFERENCES publisher (publisherID)
   ) TYPE=INNODB;


--
-- Table structure for table 'authorsISBN'
--
CREATE TABLE authorISBN (
     authorID int(11) NOT NULL,
     isbn varchar(20) NOT NULL,
     authors_authorID INT NOT NULL,
     titles_isbn varchar(20) NOT NULL,
     INDEX (authors_authorID),
     FOREIGN KEY(authors_authorID) REFERENCES authors (authorID),
     INDEX (titles_isbn),
     FOREIGN KEY(titles_isbn) REFERENCES titles(isbn)
   ) TYPE=INNODB;


# example insert statements

INSERT INTO authors values (1,"H.M.","Deitel");

INSERT INTO titles values ("0130895601","Advanced Java 2 Platform How to Program",2001,1,"X",NULL);

INSERT INTO publisher values (1, "Printice Hall");



I am not able to use any insert statements with my authorISBN table. All the about insert statemetns works fine, but when i try to insert into authorISBN, i get an error:

Error: 1216: Can not add or update a child row: a foreign key constraint failure.


Can someone please create a database and add the tables and help me out here. MySQL manual does not explain this well. Thanx in advance.

-Nikolas
 
Old January 8th, 2004, 06:17 PM
Authorized User
 
Join Date: Jan 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Nevermind, i fixed the problem. In authorISBN table, i just removed 'NOT NULL' exp from the Index declaration.

Nikolas






Similar Threads
Thread Thread Starter Forum Replies Last Post
Whats the work around? aaronmuslim XSLT 5 March 26th, 2008 04:10 PM
Whats this book like? PaulBerry BOOK: Beginning C# 2005 Databases 0 January 25th, 2008 12:55 PM
Whats this error rajanikrishna ASP.NET 2.0 Basics 0 February 17th, 2006 02:10 AM
Whats wrong? Agentofnight Beginning PHP 3 April 17th, 2005 04:11 AM
Whats the diff?? nsakic XSLT 2 January 17th, 2004 07:11 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.