0

Hi I am trying to use the CHECK constraint to stop one row from being larger than the other.

create table myTable (
begin int(10),
end int(10),
check (begin < end)
);

The table is created however there is no constraint being applied when inserting rows.

Any help on what I'm doing wrong would be great.

4
  • is this in SQL Server? I'm just quite unsure how'd you successfullly created the table with int(10). Anyway you can check the constraint created using 'sp_help myTable'. Commented Jun 5, 2013 at 3:43
  • What RDBMS are you using (MySql, SQL Server, Oracle etc.)? Commented Jun 5, 2013 at 4:08
  • @hallie oracle is what im using Commented Jun 5, 2013 at 4:53
  • Can you give an example of inserts that should be rejected but aren't? Your current table definition allows NULLs, and NULL treatment by constraints can surprise some people, if that's a factor. Commented Jun 5, 2013 at 6:04

1 Answer 1

1

You have to give a name to the constraint.

CREATE TABLE myTable
(
   begin   NUMBER (10),
   end     NUMBER (10),
   CONSTRAINT constr_begin_end CHECK (begin < end)
);

Also, begin and end are keywords in Oracle. Avoid this in column names, variable names.

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.