Check Constraint To Restrict The Registration Date To Dates After August 26, 2005
Need some help with this: Create a table called TEMP_STUDENT with the following columns and constraints: a column STUD_ID for the student ID and is the primary key, a column F
Solution 1:
You have several errors in your expression:
- It's
to_date()notto date()(note the underscore) - a function call must not be put into single quotes, so it's
to_date(..), not'to_date(...)' - you repeated the column after the
>operator which is also wrong.
So the correct expression is this:
CONSTRAINT chk_REGISTRATION_DATE
CHECK (REGISTRATION_DATE > TO_DATE('2005-08-26', 'yyyy-mm-dd'))
Note that you should always specify a format when using to_date() otherwise the conversion is subject to the NLS setting of the server and the client and might produce strange errors.
And even if you use a format mask you should not use a literal that depends on the current NLS language. AUGUST might not work for all languages as the month name. It's better to use the month number.
Solution 2:
Try this
CREATETABLE Temp_Student
(STUD_ID NUMBER (8,0),
FIRST_NAME VARCHAR2(25) NOTNULL,
LAST_NAME VARCHAR2(25) NOTNULL,
ZIP VARCHAR2(5),
REGISTRATION_DATE DATENOTNULL,
CONSTRAINT STUD_ID_PK PRIMARY KEY(STUD_ID),
CONSTRAINT ZIP_FK FOREIGN KEY (ZIP)
REFERENCES ZIPCODE (ZIP),
CONSTRAINT chk_REGISTRATION_DATE CHECK (REGISTRATION_DATE> TO_DATE('26-AUGUST-2005'))
)
Post a Comment for "Check Constraint To Restrict The Registration Date To Dates After August 26, 2005"