MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 29th, 2012, 06:43 PM
hiya1992 hiya1992 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 2 hiya1992 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 56 m 45 sec
Reputation Power: 0
MySQL syntax help

2 SQL codes below. Keep getting an error on the second one.

Code:
Original - Code
    Create Table Store( StoreID int IDENTITY, town nvarchar(25) NOT NULL, address nvarchar(50) NOT NULL, PRIMARY KEY(StoreID) )





Code:
Original - Code
    Create Table Order( orderNumber int PRIMARY KEY, orderDate datetime Not Null, completed bit Not Null, discount numeric(2,1) Not Null, CONSTRAINT FK_Order_StoreID FOREIGN KEY(StoreID) REFERENCES (StoreID) )

Reply With Quote
  #2  
Old November 29th, 2012, 08:29 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,373 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 6 h 54 m 33 sec
Reputation Power: 4140
you'll get several errors if you actually run those statements in mysql

in the first one, IDENTITY is invalid for mysql

in the second one, ORDER is a reserved word, so you cannot name your table this without escaping it with backticks, and the foreign key declaration won't work because you forgot to include the StoreID column in the table, and you also didn't say which table it references
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #3  
Old November 29th, 2012, 08:44 PM
hiya1992 hiya1992 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 2 hiya1992 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 56 m 45 sec
Reputation Power: 0
Quote:
Originally Posted by r937
you'll get several errors if you actually run those statements in mysql

in the first one, IDENTITY is invalid for mysql

in the second one, ORDER is a reserved word, so you cannot name your table this without escaping it with backticks, and the foreign key declaration won't work because you forgot to include the StoreID column in the table, and you also didn't say which table it references


Thankyou, sorry i did notice that stupid slip up for the table referencing. I'm not sure what you mean by the IDENTITY being invalid. I hate to bother you further but is there an easy explanation for that?

I'm still getting a CONSTRAINT error as well using the below codes.

Code:
Original - Code
    Create Table Orders( orderNumber bigint Not Null, orderDate datetime Not Null, completed bit Not Null, discount numeric(2,1), PRIMARY KEY(orderNumber) CONSTRAINT FK_Orders_Store FOREIGN KEY(StoreID) REFERENCES Store(StoreID) CONSTRAINT FK_Orders_Pizza FOREIGN KEY(itemCode) REFERENCES Pizza(itemCode) )


Code:
Original - Code
    Create Table Store( StoreID int IDENTITY, town nvarchar(25) NOT NULL, address nvarchar(50) NOT NULL, PRIMARY KEY(StoreID) )


Code:
Original - Code
    Create Table Pizza( itemCode int IDENTITY, pizzaName nvarchar(25) NOT NULL, baseType nvarchar(20) NOT NULL, PRIMARY KEY(itemCode) )

Reply With Quote
  #4  
Old November 30th, 2012, 02:50 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 2,349 swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 4 Days 7 h 27 m 6 sec
Reputation Power: 390
If you get an error, post the complete error message.

Reply With Quote
  #5  
Old November 30th, 2012, 02:57 AM
shammat shammat is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Oct 2003
Location: Germany
Posts: 2,685 shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 3 Days 19 h 53 m 13 sec
Reputation Power: 284
And please read the manual before proceeding:

http://dev.mysql.com/doc/refman/5.5/en/create-table.html
__________________
I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags.
http://forums.devshed.com/misc.php?do=bbcode#code

Tips on how to ask better questions:
http://tkyte.blogspot.de/2005/06/how-to-ask-questions.html
http://wiki.postgresql.org/wiki/SlowQueryQuestions
http://catb.org/esr/faqs/smart-questions.html

Reply With Quote
  #6  
Old November 30th, 2012, 04:26 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,373 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 6 h 54 m 33 sec
Reputation Power: 4140
Quote:
Originally Posted by hiya1992
I'm still getting a CONSTRAINT error as well using the below codes.
because you're trying to declare a foreign key for a column that you have not included in the table

wrong --

CREATE TABLE wrong
( foo INTEGER
, bar INTEGER
, CONSTRAINT x FOREIGN KEY (fap) REFERENCES humpty ( dumpty )
)

right --

CREATE TABLE right
( foo INTEGER
, bar INTEGER
, fap INTEGER
, CONSTRAINT x FOREIGN KEY (fap) REFERENCES humpty ( dumpty )
)

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > MySQL syntax help

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap