Adding table constraints, PL-SQL Programming

Adding Table Constraints

ALTER TABLE ENROLMENT ADD CONSTRAINT NameNotNull

CHECK (Name IS NOT NULL) ;

ALTER TABLE ENROLMENT ADD CONSTRAINT PK_StudentId_CourseId

PRIMARY KEY (StudentId, CourseId) ;

  1. ALTER TABLE ENROLMENT specifies that the definition of base table ENROLMENT is to be modified in some way, such as adding or dropping a column, adding or dropping a constraint (among other things).
  2. ADD CONSTRAINT NameNotNull specifies that in fact a constraint is being added to the definition of ENROLMENT, and the name by which that constraint can subsequently be referred to is NameNotNull. For example, the name would be needed if the constraint were later to be dropped, or perhaps it could appear in an error message when an attempted update is rejected for violating that constraint. Similar comments apply to ADD CONSTRAINT PK_StudentId_CourseId.
  3. CHECK (Name IS NOT NULL) specifies a truth-valued expression, Name IS NOT NULL, that must be satisfied by each row of every table that is assigned to ENROLMENT. If the current value of ENROLMENT fails to satisfy this constraint, then the ALTER TABLE statement fails.
  4. PRIMARY KEY ( StudentId, CourseId ) used for constraint. Again, the ALTER TABLE statement fails if the constraint is not satisfied by the current value of ENROLMENT.
Posted Date: 1/18/2013 2:57:17 AM | Location : United States







Related Discussions:- Adding table constraints, Assignment Help, Ask Question on Adding table constraints, Get Answer, Expert's Help, Adding table constraints Discussions

Write discussion on Adding table constraints
Your posts are moderated
Related Questions
CHECK Constraints in SQL A CHECK constraint is a table constraint defined using the key word CHECK, as already illustrated in several examples in this chapter. In particular,

Grouping and Ungrouping in SQL Example specifying EXAM_MARK in place of COURSE in the main FROM clause. Example: Obtaining C_ER2 from EXAM_MARK SELECT CourseId, CAST

Initializing and Referencing Collections Until you initialize a collection, a nested table or varray is automatically null (i.e. the collection itself is null, not its elements)

Using Aggregation on Nested Tables Example is the most direct translation of its counterpart in the theory book that can be obtained in SQL but it is so over-elaborate that no

Product-specific Packages The Oracle and different Oracle tools are supplied with the product-specific packages which help you to build the PL/SQL-based applications. For illus

Manipulating Local Collections Within PL/SQL, to manipulate the local collection, by using theĀ  TABLE and CAST operators . The operands of CAST are a collection declared locally

Using raise_application_error The Package DBMS_STANDARD that is supplied with Oracle gives language facilities that help your application to interact with Oracle. For illustra

Parameter and Keyword Description: cursor_name: This identifies an explicit cursor formerly declared within the present scope. cursor_variable_name: These identif

Functions The function is a subprogram which can take parameters and be invoked. Normally, you can use a function to calculate a value. The function has 2 sections: the specifi

Attributes: Just similar to variable, an attribute is declared with a name and datatype. The name should be exclusive within the object type. The datatype can be any Oracle ty