Author |
Topic |
kofijr
Starting Member
2 Posts |
Posted - 2015-01-14 : 14:15:14
|
I am new to sql and trying to create a check command that ensures only letter A'B','c','D','E','F','G can be inserted into the table, is this even applicable? Heres my rough syntaxCreate Table GRADE (Grade VARCHAR2(1) CONSTRAINT pk_Grade PRIMARY KEY CONSTRAINT check_grade CHECK (substr(Grade = 'A','B','c','D','E','F','G')), Salary_Scale VARCHAR2(2) CONSTRAINT check_SScale CHECK (substr(Salary_Scale = 'S1' or 'S2')),)/what is wrong with this SQL syntax?Thank you. |
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2015-01-14 : 15:44:13
|
There's lots wrong with the syntax! 1. THere is no varchar2 type2. there's no substr function in sql, though there is a substring function. Secondly, the substring function takes three parameters(string, start, end) and an expression like Grade = 'A','B','c','D','E','F','G' is not allowed (I'm not even sure what it would mean!)However, you can try this:Create Table GRADE (Grade VARCHAR(1) CONSTRAINT pk_Grade PRIMARY KEYCONSTRAINT check_gradeCHECK (grade in ('A','B','c','D','E','F','G')),Salary_Scale VARCHAR(2) CONSTRAINT check_SScaleCHECK (Salary_Scale in ('S1', 'S2')),) |
|
|
kofijr
Starting Member
2 Posts |
Posted - 2015-01-14 : 22:39:37
|
Thanks for the syntax, but damn still not working. |
|
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2015-01-15 : 00:52:32
|
What's not working |
|
|
ScottPletcher
Aged Yak Warrior
550 Posts |
Posted - 2015-01-15 : 11:20:55
|
[code]Create Table GRADE (Grade nchar(1) CONSTRAINT pk_Grade PRIMARY KEY CONSTRAINT check_grade CHECK (Grade in ('A','B','c','D','E','F','G')),Salary_Scale nchar(2) CONSTRAINT check_SScale CHECK (Salary_Scale in ('S1', 'S2')))[/code] |
|
|
|
|
|