5 Replies - 7148 Views - Last Post: 11 November 2012 - 10:44 AM

#1 RourkeOkeffe   User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 89
  • Joined: 27-October 12

Syntax Error in create table

Posted 11 November 2012 - 09:48 AM

CREATE TABLE Routes(Route Number VARCHAR(10)NOT NULL,Frequency VARCHAR(25)NOT NULL,Start INTEGER NOT NULL,Destination INTEGER NOT NULL,Operator VARCHAR(20)NOT NULL,
FOREIGN KEY (Operator) REFERENCES Operators(Operator)
FOREIGN KEY (Start,Destination)REFERENCES BusStop(BusStopId)
PRIMARY KEY(Start,Destination,Operator)) ENGINE=InnoDB;

Can someone tell me what is incorrect about this.I am trying to create a combined primary key
and use foreign keys to reference fields in the table.

Is This A Good Question/Topic? 0
  • +

Replies To: Syntax Error in create table

#2 darek9576   User is offline

  • D.I.C Lover

Reputation: 204
  • View blog
  • Posts: 1,737
  • Joined: 13-March 10

Re: Syntax Error in create table

Posted 11 November 2012 - 10:03 AM

One mistake i see, is the Route Number column:

This wont work:
create table routes(route number varchar(10));



This will:
create table routes(`route number` varchar(10));



The rest, i have no idea.
Was This Post Helpful? 1
  • +
  • -

#3 RourkeOkeffe   User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 89
  • Joined: 27-October 12

Re: Syntax Error in create table

Posted 11 November 2012 - 10:07 AM

CREATE TABLE Routes (RouteNumber VARCHAR(10)NOT NULL,Frequency VARCHAR(25)NOT NULL,Start INTEGER NOT NULL,Destination INTEGER NOT NULL,Operator VARCHAR(20)NOT NULL,
FOREIGN KEY (Operator)REFERENCES Operators(Operator),
FOREIGN KEY (Start)REFERENCES BusStop(BusStopId)
FOREIGN KEY(Destination)REFERENCES BusStop(BusStopId)
PRIMARY KEY(Start,Destination,Operator))ENGINE=InnoDB;

I have corrected the first line but it says the error is in line 4
Was This Post Helpful? 0
  • +
  • -

#4 darek9576   User is offline

  • D.I.C Lover

Reputation: 204
  • View blog
  • Posts: 1,737
  • Joined: 13-March 10

Re: Syntax Error in create table

Posted 11 November 2012 - 10:15 AM

What mistake are you getting.
Was This Post Helpful? 0
  • +
  • -

#5 RourkeOkeffe   User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 89
  • Joined: 27-October 12

Re: Syntax Error in create table

Posted 11 November 2012 - 10:18 AM

It says its a syntax error.I want to use the foreign keys as part of the primary key.
Was This Post Helpful? 0
  • +
  • -

#6 RourkeOkeffe   User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 89
  • Joined: 27-October 12

Re: Syntax Error in create table

Posted 11 November 2012 - 10:44 AM

Sorted it now just needed some commas.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1