Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2010

    Unanswered: What exactly are constraints

    I have the following example and am trying to understand what Constraints are doing. This is the code:

    CREATE TABLE donation
    (	donation_id 	NUMBER 
    			CONSTRAINT donation_id_pk PRIMARY KEY,
    	donator 	NUMBER
    			CONSTRAINT donation_donator_nn NOT NULL
    			CONSTRAINT donation_donator_fk REFERENCES person(id),
    	type 		CHAR(1) 
    			DEFAULT 'C'
    			CONSTRAINT donation_type_cc CHECK(type IN('C','M','V'))
    			CONSTRAINT donation_type_nn NOT NULL,
    	amount 		NUMBER(8,2)
    			CONSTRAINT donation_amount_cc CHECK (amount > 0 AND amount <= 100),
    	dateDonate 	DATE,
    	note 		VARCHAR2(80));
    From what I understand the constraint enforces a rule? So to check and make sure a value is not null or a value is in a certain range?


  2. #2
    Join Date
    Mar 2006
    Or is a value that actually exists in another table (foreign key constraint).
    Now back on Oracle. The more things change, the more they stay the same.

  3. #3
    Join Date
    Aug 2003
    Where the Surf Meets the Turf @Del Mar, CA
    Provided Answers: 1
    When all else fails, Read The Fine Manual

    Data Integrity
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts