2

I am trying to create a simple table with a few columns. I would like to add a check constraint to one of the columns, see below:

create table jobs (
    JOB_ID varchar(10) not null,
    JOB_TITLE varchar(35) not null,
    MIN_SALARY decimal(6,0),
    MAX_SALARY decimal(6,0) 
    CHECK(MAX_SALARY<=25000)
    );

This returns an error for the CHECK line.

A comma or closing bracket was expected. (near CHECK)

If I add a comma like to the previous line; MAX_SALARY decimal(6,0),, I am returned with more errors:

A symbol name was expected! A reserved keyword can not be used as a column name without backquotes.

Unexpected beginning of statement near MAX_SALARY

Unexpected beginning of statement near 25000

August Williams
  • 907
  • 4
  • 20
  • 37

1 Answers1

3

Updated:

Just Create Table Without CHECK and Then After Alter it:

  create table jobs (
    JOB_ID varchar(10) not null,
    JOB_TITLE varchar(35) not null,
    MIN_SALARY decimal(6,0),
    MAX_SALARY decimal(6,0)
    );

ALTER TABLE jobs ADD CHECK (MAX_SALARY<=25000);

OR


In MySQL:

create table jobs (
    JOB_ID varchar(10) not null,
    JOB_TITLE varchar(35) not null,
    MIN_SALARY decimal(6,0),
    MAX_SALARY decimal(6,0), 
    CHECK(MAX_SALARY<=25000)    
    );

SQL Server / Oracle

 create table jobs (
    JOB_ID varchar(10) not null,
    JOB_TITLE varchar(35) not null,
    MIN_SALARY decimal(6,0),
    MAX_SALARY decimal(6,0) CHECK(MAX_SALARY<=25000)

    );

NOTE: CHECK constraints are not supported by MySQL But You Can Use it, as i declared , but its not give you an output !!

Hack it
  • 405
  • 2
  • 10