Adding Entity Integrity Constraints Assignment Help

Assignment Help: >> Data Integrity - Adding Entity Integrity Constraints

Adding Entity Integrity Constraints

Primary key and unique key both constraints can be added at the time of creation of tables. Let us suppose creating a table called item_master that contains item_code, item_name and unit_price.

Example

Create table Item_master (item_code number primary key,
       Item_name varchar2 (20) unique,
      Unit_price number (9,2)
       );

The table is created with the constraints if a constraint is provided without specifying the name of the constraint An Oracle by default assigns a name to the constraint which is unique across. The constraint begins with ‘SYS_C’ followed through some numbers.

After creation, records are inserted into the table as below:

INSERT INTO item_master VALUES (1,’Pencils’, 2.50);
If the same command is executed again, it increase an error.
INSERT INTO item_master VALUES (1,'Pencils', 2.50);
*
ERROR at line 1:
ORA-00001: unique constraint (HEMA.SYS_C00769) violated

By looking at this error message the user should not understand that value is desecrated. In order to prevent these conditions, a name has to be provided for every constraint that is easy to read. Refining the above instance,

Create table Item_master(item_code number CONSTRAINT pkit_code primary key, Item_name varchar2(20) CONSTRAINT unqit_name unique, Unit_price number(9,2)
);

Naming the constraints always gives better readability.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd