检查限制将注册日期限制在2005年8月26日之后 [英] CHECK constraint to restrict the registration date to dates after August 26, 2005
问题描述
需要一些帮助:
创建一个名为TEMP_STUDENT的表,其中包含以下列和
约束:列STUD_ID对于学生ID,是主要的
密钥,学生姓名列FIRST_NAME,学生姓氏列LAST_NAME
,ZIP
列的外键列ZIP在学生数据库架构的ZIPCODE表中,
列REGISTRATION_DATE为NOT NULL,并有一个CHECK约束
,以将注册日期限制为2005年8月26日之后的日期。ALL
约束必须被命名。我必须这样做:
我得到这个:
CREATE TABLE Temp_Student
(STUD_ID NUMBER(8,0),
FIRST_NAME VARCHAR2(25)NOT NULL,
LAST_NAME VARCHAR2(25 )NOT NULL,
ZIP VARCHAR2(5),
REGISTRATION_DATE DATE NOT NULL,
CONSTRAINT STUD_ID_PK PRIMARY KEY(STUD_ID),
CONSTRAINT ZIP_FK FOREIGN KEY(ZIP)
参考ZIPCODE(ZIP),
CONSTRAINT chk_REGISTRATION_DATE CHECK(REGISTRATION_DATE> REGISTRATION_DATE'TO DATE('26 -AUGUST-2005'))
);
任何有关最后一个约束的帮助,将不胜感激,我不知道我在做什么。 / p>
继续收到此消息:
CONSTRAINT chk_REGISTRATION_DATE CHECK(REGISTRATION_DATE> REGISTRATION_DATE 'to DATE('26 -AUGUST-2005')')
*
第10行的错误:
ORA-00907:缺少右括号
您的表达式中有几个错误:
- 这是
to_date()
notto date()
(注意下划线) - 一个函数调用不能放在单引号中,所以它是
to_date(..)
,而不是'to_date (...)'
- 您在
>
运算符之后重复列,这也是错误的
所以正确的表达是这样的:
CONSTRAINT chk_REGISTRATION_DATE
CHECK(REGISTRATION_DATE> TO_DATE('2005-08-26','yyyy-mm-dd'))
请注意您应该 始终 使用 to_date()
指定格式,否则转换将受服务器的NLS设置和客户端可能会产生奇怪的错误。
即使您使用格式掩码,也不应使用依赖于当前NLS语言的文字。 AUGUST
可能不适用于所有语言作为月份名称。最好使用月份号码。
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 FIRST_NAME for student first name, a column LAST_NAME for student last name, a column ZIP that is a foreign key to the ZIP column in the ZIPCODE table of the Student Database Schema, and a column REGISTRATION_DATE that is NOT NULL and has a CHECK constraint to restrict the registration date to dates after August 26, 2005. ALL CONSTRAINTS MUST BE NAMED. Both the first_name and last_name columns are required.
I got this:
CREATE TABLE Temp_Student
(STUD_ID NUMBER (8,0),
FIRST_NAME VARCHAR2(25) NOT NULL,
LAST_NAME VARCHAR2(25) NOT NULL,
ZIP VARCHAR2(5),
REGISTRATION_DATE DATE NOT NULL,
CONSTRAINT STUD_ID_PK PRIMARY KEY(STUD_ID),
CONSTRAINT ZIP_FK FOREIGN KEY (ZIP)
REFERENCES ZIPCODE (ZIP),
CONSTRAINT chk_REGISTRATION_DATE CHECK (REGISTRATION_DATE> REGISTRATION_DATE 'TO DATE('26-AUGUST-2005'))
);
Any help with the last constraint, it would be much appreciated i have no idea what im doing.
keep getting this message:
CONSTRAINT chk_REGISTRATION_DATE CHECK (REGISTRATION_DATE> REGISTRATION_DATE 'TO DATE('26-AUGUST-2005')')
*
ERROR at line 10:
ORA-00907: missing right parenthesis
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.
这篇关于检查限制将注册日期限制在2005年8月26日之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!