SQL: Check constraints syntax errors?

72 Views Asked by At

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

There are 1 best solutions below

0
AudioBubble On BEST ANSWER

The create constraint is wrong, and string constants need to be supplied in single quotes '. Double quotes " are for identifiers

CREATE TABLE FAGFELT
(
   bok varchar (255) PRIMARY KEY,
   felt varchar (255), --<< you need a comma here
   CONSTRAINT chk_felt 
       CHECK (felt IN('databaser', 'programmering', 'matematikk', 'statistikk', 'kjemi', 'fysikk'))
);