Error and doubts FireBird sql

0

I own this table code

CREATE TABLE news (
    id_news INTEGER NOT NULL,
    title VARCHAR(128) NOT NULL,
    slug VARCHAR(128) NOT NULL,
    text TEXT NOT NULL,
    PRIMARY KEY (id_news),
    KEY slug (slug)
);

You are experiencing the following error

  

Statement failed, SQLSTATE = 42000

     

-Dynamic SQL Error

     

- SQL error code = -104

     

-Token unknow-line 7, column 18

     

- (

I believe the problem is in the "KEY slug (slug)" part, I would like an explanation of what this attribute means and the reason for the error.

    
asked by anonymous 27.03.2018 / 16:30

2 answers

3

I do not know the use of the word KEY alone in the command CREATE TABLE , KEY is combined like this:

PRIMARY KEY - to set the primary key
FOREIGN KEY - to set a foreign key

How could a unique feature of the firebird look in the documentation but really there is not only the reserved word KEY in CREATE TABLE . See the documentation here: CREATE TABLE firebird

There is then a syntax error on line KEY slug (slug) . It remains to be seen if slug does foreign key relation with another table, but in this case the correct syntax would be:

FOREIGN KEY (slug) REFERENCES nome-da-tabela (nome-do-campo) 
    
27.03.2018 / 16:46
0

It is not clear in the description of the problem the purpose of setting the news.slug attribute to key and how it is following documentation from a framework I believe I have no knowledge of the problem domain.

But the error message is related to a syntax problem. To create a candidate key, that is, an attribute that will receive a value that can not be repeated but is not the primary key, in firebird it follows the following template:

ALTER TABLE nometabela 
ADD CONSTRAINT nomeindice UNIQUE (nomeatributo);

or

CREATE UNIQUE INDEX nomeindice ON nometabela (nomeatributo);
    
08.05.2018 / 20:04