Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-17-2012, 07:29 AM   PM User | #16
crewson548
New Coder

 
Join Date: Oct 2012
Posts: 11
Thanks: 3
Thanked 0 Times in 0 Posts
crewson548 is an unknown quantity at this point
Please suggest me with some more example with this load problems>
can any one tell me the peak load point for an server?
crewson548 is offline   Reply With Quote
Old 12-06-2012, 09:27 PM   PM User | #17
markman641
Regular Coder

 
Join Date: Jul 2011
Posts: 246
Thanks: 58
Thanked 1 Time in 1 Post
markman641 has a little shameless behaviour in the past
Quote:
Originally Posted by Old Pedant View Post
As I see it you need these tables:
Code:
CREATE TABLE Categories (
    catid INT AUTO_INCREMENT PRIMARY KEY,
    catname VARCHAR(100)
);

CREATE TABLE Countries (
    coid INT AUTO_INCREMENT PRIMARY KEY,
    coname VARCHAR(100)
);

CREATE TABLE Customers (
    custid INT AUTO_INCREMENT PRIMARY KEY,
    coid INT FOREIGN KEY REFERENCES countries(coid),
    custname VARCHAR(100))
);

CREATE TABLE Offers (
    offerid INT AUTO_INCREMENT PRIMARY KEY
    catid INT FOREIGN KEY REFERENCES categories(catid),
    offerdetails .... one or more fields to describe the offer ...
);

CREATE TABLE OffersByCountry (
    offerid INT FOREIGN KEY REFERENCES offers(offerid),
    coid INT FOREIGN KEY REFERENCES countries(coid)
);

CREATE TABLE CompletedOffers (
    custid INT FOREIGN KEY REFERENCES custormers(custid),
    offerid INT FOREIGN KEY REFERENCES offers(offerid)
);
The foreign key reference in magenta there may not be necessary, but it is likely a good idea.

The syntax there for the foreign keys isn't quite correct for MySQL, but it's a compact form that easy to read for a post like this.

Quote:
SQL query:

CREATE TABLE Customers(

custid INT AUTO_INCREMENT PRIMARY KEY ,
coid INT FOREIGN KEY REFERENCES countries( coid ) ,
custname VARCHAR( 100 )
));

MySQL said:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FOREIGN KEY REFERENCES countries(coid),
custname VARCHAR(100))
)' at line 3
The same error appears for all tables after that too.

Last edited by markman641; 12-06-2012 at 09:33 PM..
markman641 is offline   Reply With Quote
Old 12-06-2012, 10:25 PM   PM User | #18
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,055 Times in 4,024 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Look at what I wrote:
Quote:
The syntax there for the foreign keys isn't quite correct for MySQL, but it's a compact form that easy to read for a post like this.
The correct syntax is:
Code:
CREATE TABLE Customers (
    custid INT AUTO_INCREMENT PRIMARY KEY ,
    coid INT,
    custname VARCHAR( 100 ),
    CONSTRAINT FOREIGN KEY fk_customers_coid ( coid ) REFERENCES countries( coid ) 
 );
You don't have to give the foreign key a name (the part in red there). MySQL will create a name for you if you don't, and you can then find the created name by doing
Code:
SHOW CREATE TABLE Customers;
You can see why I prefer the more compact version I use when posting. It's clearer what the intent is, even if the syntax isn't quite right.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 12-06-2012, 10:28 PM   PM User | #19
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,055 Times in 4,024 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Here's an example of the name MySQL generates if you omit it. This is from SHOW CREATE TABLE:
Code:
CREATE TABLE `customers` (
  `custid` int(11) NOT NULL AUTO_INCREMENT,
  `coid` int(11) DEFAULT NULL,
  `custname` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`custid`),
  KEY `coid` (`coid`),
  CONSTRAINT `customers_ibfk_1` FOREIGN KEY (`coid`) REFERENCES `countries` (`coid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:13 PM.


Advertisement
Log in to turn off these ads.