Firebird sql error and doubts

Asked

Viewed 256 times

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)
);

That is presenting 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.

2 answers

3

I do not know the use of the word KEY isolated in control only CREATE TABLE, KEY is thus combined:

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

How could it be a Feature exclusive to the firebird searched in the documentation but really there is not only the word reserved KEY in CREATE TABLE. See here the documentation: CREATE TABLE Firebird

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

FOREIGN KEY (slug) REFERENCES nome-da-tabela (nome-do-campo) 
  • I am following the documentation of the Codeigniter framework and it asks to create a table using this key Slug, can you check and help me find another alternative to what is requested? Here’s the page I’m reading https://www.codeigniter.com/user_guide/tutorial/news_section.html

  • 2

    Hold on, you tagged firebird on the question, but this link is for MySQL, came to read? Connect to your database and run the SQL command Below (Mysql)

  • In MySQL, KEY how it was used to create an index, and this works only in the MySQL, if you try to run in a database other than what you are recommending on the link will not work

0

It is not clear in the description of the problem the objective of defining as key the attribute news.Slug and as this following a documentation of a framework I believe I have no knowledge of the domain of the problem.

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 cannot be repeated, but is not the attribute identified (Primary key), in Firebird follows the following model:

ALTER TABLE nometabela 
ADD CONSTRAINT nomeindice UNIQUE (nomeatributo);

or

CREATE UNIQUE INDEX nomeindice ON nometabela (nomeatributo);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.