below, I have create a table using oracle sql.

How can I change so that number of credits for a course is always between 0 and 6. Any idea how can i do this?

CREATE TABLE COURSES
  (COURSE VARCHAR(6),
   DESCRIPTION VARCHAR(60),
   CREDITS INT,
   CONSTRAINT pk PRIMARY KEY (COURSE));
Member Avatar for diafol

I would imagine that data validation could be done with server-side code. I don't use Oracle myself, but I'm assuming that the datatype that you need is TT_TINYINT (0 to 255). I've seen some people mention ENUM, but IMO this is not appropriate for simple integers.

Are you using any server-side language?

but cant you enter 7 in TT_TINYINT? i need to do it so range is from 0 to 6. I am using oracle mysql.

Member Avatar for diafol

Read my post. I said it accepts 0 to 255. So yes, it can. There is no specific datatype that I know of for what you're asking. Are you able to validate server-side? You don't give any info wrt how you're insering data

i am just inserting data by using mysql(Oacle) insert statments.

Member Avatar for diafol

Ah, ok, in that case, I don't know. You could try to use an IF function maybe (??) but that means you'd have to implement it in the actual SQL query which is probably not what you want. Perhaps you could use a related table using a constraint - make the credits field an FK of a credits table PK:

credits table
PK 0-6
Other fields??

So, beyond this I'm not much help - sorry.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.