1

A column should have its field as either 'cl', 'sl' or 'el'. How to add such constraints in oracel sql ?

2 Answers 2

2

You can try to use the CHECK constraint like this:

CREATE TABLE myTable
(
   id int NOT NULL,
   col varchar(10)
   CONSTRAINT chk_col CHECK (col IN ('cl', 'sl', 'el' ))
)

or use ALTER command like

alter table mytable 
       add col varchar(10) 
       constraint chk_col check(col IN ('cl', 'sl', 'el' ))
Sign up to request clarification or add additional context in comments.

1 Comment

@gopal:- Use the alter table command which I have added in my answer,
0

If the column is to contain 'cl', 'sl' or 'el' only, then these strings certainly have meanings. You can simply add a check constraint to your table, but that would leave the matter rather undocumented.

For this reason you may want to add a small lookup table instead:

leave  description
cl     Casual Leave
sl     Sick Leave 
el     Earned Leave

In your existing table you'd simply put a foreign key constraint to that lookup table then.

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.