| | |
help with coloumn values
Please support our Oracle advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
hi
I have a coulumn named Status which can have only three values:
1. Available (Default)
2. Unavailable
3. CheckedOut
How can I add this functionality while creating the table? i.e. while creating the table itself how can i specify that the column can hold only these 3 values and populate all rows with the default value?
Please help
I have a coulumn named Status which can have only three values:
1. Available (Default)
2. Unavailable
3. CheckedOut
How can I add this functionality while creating the table? i.e. while creating the table itself how can i specify that the column can hold only these 3 values and populate all rows with the default value?
Please help
God made the World
We program IT
We program IT
•
•
Join Date: Jun 2009
Posts: 435
Reputation:
Solved Threads: 82
Use check constraints. A check constraint allows you to specify a condition on each row in a table.
Try this
Try this
Oracle Syntax (Toggle Plain Text)
CREATE TABLE YourTableName ( COLUMN 1..., column2..., STATUS numeric(1), CONSTRAINT check_status CHECK (STATUS IN (1,2,3)) );
Last edited by Ramesh S; Aug 1st, 2009 at 4:00 am.
you nee to create a table with check constraint and default values.
try this
try this
sql Syntax (Toggle Plain Text)
CREATE TABLE table1 (ID INT, status varchar2(10) DEFAULT 'Available', CONSTRAINT con_chk1 CHECK (status IN ('Available','Unavailable','CheckedOut') ))
Share your Knowledge.
•
•
Join Date: Jun 2009
Posts: 13
Reputation:
Solved Threads: 1
You can create the constraint at the moment of the creation of the table
Or you can create the constraint on the fly:
Oracle Syntax (Toggle Plain Text)
DROP TABLE itself; CREATE TABLE itself ( status VARCHAR2(11) DEFAULT 'Available' CHECK (status IN ('Available','Unavailable','CheckedOut')) );
Or you can create the constraint on the fly:
Oracle Syntax (Toggle Plain Text)
ALTER TABLE itself ADD CONSTRAINT ck_itself_status CHECK ((status IN ('Available','Unavailable','CheckedOut')));
•
•
Join Date: Feb 2008
Posts: 20
Reputation:
Solved Threads: 4
Pretty much as mentioned the constraints are the way to go. You can use a lookup table to easily do this as well. So you have your lkp_Status table, just with those 3 values. And you can create a primary foreign key constraint as well. This way in the future if a value is added and there needs to be 4 values you can just add the value in the lookup table and the primary foreign key relationship remains the same. It doesn't need to change.
![]() |
Similar Threads
- passing values of Select box from JSP to Action class thru form Bean (JSP)
- Gridview coloumn data to come in Bulleted list (ASP.NET)
- displaying the values in the combobox (VB.NET)
- ASCII values and characters (C)
- Add values of cl (Visual Basic 4 / 5 / 6)
- The improtance of replacing values in pointers (C)
- can't set paging file values (Windows NT / 2000 / XP)
- Posting values to a payment gateway without using a form (ASP.NET)
- checkbox values (JSP)
Other Threads in the Oracle Forum
- Previous Thread: vista DSN name oracle odbc driver missing
- Next Thread: Internal Server Error
| Thread Tools | Search this Thread |
2009predictions acquisition amazon.com bartz bernanke cia citrix cloudcomputing crm database dell economy editor enterprise enterprise2.0 enterprisesoftware federalreserve forbes hp ibm intellipedia internet larryellison layoffs linux loughridge mediawiki michaeljackson microsoft neverland nortel notebooks oil operatingsystem oracle palm rimm saas salesforce sap seagate socialcomputing sql sun sybase technologystocks virtualiron virtualization vmware wiki wikipedia xen yahoo zoho






