Error in sqlite3 foreign or foreigin

2

I created a database in sqlite3 in version 3.9.2 and had problems with the foreign key.

alter table table_01 add column tab_2 integer foreign key references table_02(id);
    // Esse deu erro de sintaxe no foreign key
    alter table table_01 add column tab_2 integer foreigin key references table_02(id);
    // Já esse, adicionou o campo com sucesso.

As it's in the code, gdb has accepted foreigin instead of foreign , could someone please tell me something about it?

    
asked by anonymous 14.02.2016 / 01:50

1 answer

2

Actually, when passing foreigin key , if you are using Sqlitestudio, it understands that you are passing the type, along with integer . See the print of the same query that I circled here:

Insert Query (same as you did):

Howthecolumnwasafterinsertion:

Itcanbeseenthatthecolumnwasaddedasforeignkey,butthesyntaxusedwasignoredforthispurpose.

Ascanbeseen in this SOEN response , the correct syntax for this change is:

ALTER TABLE tabela ADD COLUMN coluna TIPO REFERENCES tabela_parente(coluna_parente); 

See below in the print, the column added in tests that I did, by executing the above command:

Referencesforreading:

link

link (important to read)

    
14.02.2016 / 02:30