0

I get the following error of "syntax error at or near "foreign"" when trying to create kurinys table. Might be a silly mistake but I can't recognize it. Thank you in advance.

create table elba7430.kurinys(
    id INTEGER not null check (id > 10000),
    pavadinimas VARCHAR (55) not null,
    metai YEAR,
    meno_rusies_id INTEGER not null check (meno_rusies_id > 100),
    autoriaus_id INTEGER not null check (autoriaus_id > 1000000),
    kliento_id INTEGER not null check (kliento_id > 1000000),
    ilgis_cm DECIMAL (100,2),
    plotis_cm DECIMAL (100,2),
    kaina DECIMAL (100,2),
    primary key (id),
    foreign key (meno_rusies_id) 
        REFERENCES elba7430.meno_rusis on delete cascade on update restrict,
    foreign key (autoriaus_id) 
        REFERENCES elba7430.autorius on delete cascade on update restrict,
    foreign key (kliento_id)
        REFERENCES elba7430.klientas on delete cascade on update restrict
);


create table elba7430.meno_rusis(
        id INTEGER not null check (id > 100),
        pavadinimas VARCHAR (100) not null,
        primary key(id)
);

create table elba7430.autorius(
    id INTEGER not null check (id > 1000000),
    vardas VARCHAR (40) not null,
    pavarde VARCHAR (55) not null,
    gimimo_metai DATE,
    primary key(id)
);

create table elba7430.klientas(
    id INTEGER not null check (id > 1000000),
    vardas VARCHAR (40),
    pavarde VARCHAR (55),
    primary key(id)
);
5
  • 2
    You need to create the tables you are referencing before the tables that reference them. Commented May 2, 2022 at 15:41
  • @a_horse_with_no_name I already did it, still getting the error. Commented May 2, 2022 at 15:42
  • 1
    year isn't a data type. metai YEAR should probably be metai integer. Then it works: dbfiddle.uk/… Commented May 2, 2022 at 15:43
  • @a_horse_with_no_name still getting the same error Commented May 2, 2022 at 15:45
  • 1
    Then the code you are showing us, is not the code you are running. Because with those changes it does work: dbfiddle.uk/… Commented May 2, 2022 at 15:47

1 Answer 1

1

Changing the order of your declarations and replacing the year data type by a valid one will solve this issue, here you can replicate this: db<>fiddle

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.