By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,960 Members | 1,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,960 IT Pros & Developers. It's quick & easy.

MySQL Query Browser

P: 1
Below is a script i think should be running correctly.
Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE Sponsor(SponsorID INT, 
  2.     Companyname VARCHAR (20),
  3.     ActivitiesID INT NOT NULL,
  4.     UNIQUE(ActivitiesID),
  5.     Foreign Key (ActivitiesID)REFERENCES Activities(ActivitiesID),
  6.     Primary Key (SponsorID)) ENGINE=InnoDB;
  7.  
  8. INSERT INTO Sponsor VALUES (1,'Red Bull'),(2,'Nike')
  9. ,(3,'YMCA'),(4,'Mercedes'),(5,'Lucozade'),(6,'BHF');
  10.  
  11. CREATE TABLE Activities(ActivitiesID INT, 
  12.     Name VARCHAR (20), Maxcapacity INT, 
  13.     StartTime TIME, EndTime TIME,
  14.     Primary Key (ActivitiesID)) ENGINE=InnoDB;
  15.  
  16. INSERT INTO Activities VALUES (1,'Aerobics', 3,
  17.  '10:00:00', '12:00:00'),(2,'Bicycling', 6, 
  18. '08:30:00', '13:00:00'), (3,'Circuit', 10, 
  19. '14:00:00', '16:30:00'), (4,'Rowing', 5, 
  20. '06:00:00', '15:00:00'), (5,'Swimming', 4,
  21. '13:30:00', '17:00:00'), (6,'Badminton', 8, 
  22. '15:30:00', '17:30:00');
But whenever i run the above queries, I get 'can't create sponsor'; errono 150.

How do i correct this?
Feb 11 '12 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
from the manual:
1005 (ER_CANT_CREATE_TABLE)

Cannot create table. If the error message refers to error 150, table creation failed because a foreign key constraint was not correctly formed. If the error message refers to error 1, table creation probably failed because the table includes a column name that matched the name of an internal InnoDB table.
so it seems that something is wrong with your FK definition. (e.g. the Activities table does not exist yet)
Feb 12 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.