Peter Peter - 1 month ago 22
SQL Question

SQL: Check constraints syntax errors?

I'm trying to add a constraint to one of my columns, however i get this error message "

missing right parenthesis
". Not the first time I get this message, however I'm fairly new to SQL, so my syntax is not on par.

CREATE TABLE FAGFELT
(
bok varchar (255) PRIMARY KEY,
felt varchar (255)
CREATE CONSTRAINT chk_felt CHECK (felt IN("databaser", "programmering", "matematikk", "statistikk", "kjemi", "fysikk"))
);

Answer

You should Write like this

CREATE TABLE FAGFELT
(
bok varchar (255) PRIMARY KEY,
felt varchar (255) 
CREATE CONSTRAINT chk_felt CHECK (felt IN('databaser', 'programmering', 'matematikk', 'statistikk', 'kjemi', 'fysikk'))
)

;