Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

SQL question?

CREATE TABLE user

(

userName varchar(50) NOT NULL,

password varchar(30) NOT NULL,

PRIMARY KEY (userName)

) ;

CREATE TABLE lista

(

userName varchar(50) NOT NULL,

listaName varchar(200) NOT NULL,

listaDescription Text,

PRIMARY KEY (userName, listaName),

FOREIGN KEY (userName) REFERENCES user (userName)

ON DELETE CASCADE

ON UPDATE CASCADE

);

CREATE TABLE todo

(

listaName varchar(200) NOT NULL,

todoDescription varchar(100) NOT NULL,

active varchar(3) NOT NULL,

PRIMARY KEY (listaName,todoDescription ),

FOREIGN KEY (listaName) REFERENCES lista (listaName)

ON DELETE CASCADE

ON UPDATE CASCADE

);

Is giving me an ERROR 1005 and is not creating

"myDB.todo"

Update:

it creates the first two tables but then it gives me an error for the third one

Update 2:

isn't the space...:)

Update 3:

I am already using the database, under the user that I create for it... uhm and then I log in as that user and start creating this tables....

Update 4:

I change the name "Active" to another, still not working

4 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    Foreign key must reference ONLY on UNIQUE/PRIMARY KEY constraints. So

    CREATE TABLE todo

    (

    userName varchar(50) NOT NULL,

    listaName varchar(200) NOT NULL,

    todoDescription varchar(100) NOT NULL,

    active varchar(3) NOT NULL,

    PRIMARY KEY (listaName,todoDescription ),

    FOREIGN KEY (userName,listaName) REFERENCES lista (userName,listaName)

    ON DELETE CASCADE

    ON UPDATE CASCADE

    );

    will work.

  • Anonymous
    1 decade ago

    I dont see any reference to a database name or

    setting a WIN login or SQL account access

    where exactely do you expect this table to be defined?

  • Summer
    Lv 4
    1 decade ago

    you are missing a simple space between

  • 1 decade ago

    change field name "active"

Still have questions? Get your answers by asking now.