Faqeer
Faqeer

Reputation: 120

could not be able to build schema in mySQL

I have mysql schema

 CREATE TABLE foo(_id INTEGER PRIMARY KEY, name TEXT);

insert into foo (_id, name) values (1, "Foo A");
insert into foo (_id, name) values (2, "Foo B");

CREATE TABLE bar (_id INTEGER PRIMARY KEY, title TEXT);

insert into bar (_id, title) values (1, "Bar A");
insert into bar (_id, title) values (2, "Bar B");

CREATE TABLE bridge
(
    foo_id INT NOT NULL,  
    bar_id INT NOT NULL,  
    FOREIGN KEY (foo_id) REFERENCES foo(_id) ON UPDATE CASCADE,  
    FOREIGN KEY (bar_id) REFERENCES bar(_id) ON UPDATE CASCADE
)  

at this http://www.sqlfiddle.com/#!9/b0e77f, works good but when I try to insert data in bridge as

INSERT INTO bridge (foo_id, bar_id) values (1, 1);
INSERT INTO bridge (foo_id, bar_id) values (2, 1);

it says

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 'INSERT INTO bridge (job_id, cate_id) values (1, 1)' at line 9

Upvotes: 0

Views: 100

Answers (1)

Lukasz Szozda
Lukasz Szozda

Reputation: 175944

You need to add semicolon after CREATE TABLE bridge(...) ;:

CREATE TABLE foo(_id INTEGER PRIMARY KEY, name TEXT);

insert into foo (_id, name) values (1, "Foo A");
insert into foo (_id, name) values (2, "Foo B");

CREATE TABLE bar (_id INTEGER PRIMARY KEY, title TEXT);

insert into bar (_id, title) values (1, "Bar A");
insert into bar (_id, title) values (2, "Bar B");

CREATE TABLE bridge
(
    foo_id INT NOT NULL,  
    bar_id INT NOT NULL,  
    FOREIGN KEY (foo_id) REFERENCES foo(_id) ON UPDATE CASCADE,  
    FOREIGN KEY (bar_id) REFERENCES bar(_id) ON UPDATE CASCADE
) ;  -- HERE

INSERT INTO bridge (foo_id, bar_id) values (1, 1);
INSERT INTO bridge (foo_id, bar_id) values (2, 1);

In SQLFiddle every statement should end with terminator(;). More info in my another answer

Upvotes: 1

Related Questions