Current Position:Home > In which case composite primary key allows NULL values in it

In which case composite primary key allows NULL values in it

Update:10-11Source: network consolidation
Advertisement
Hi to all
In what case composite primary key allows nulls in it.
Let us suppose, I created a composite primary key with 2 attributes.
CREATE TABLE sample
BNK_Id NUMBER(6),
BNK_Name VARCHAR2(20),
CONSTRAINT BNK_Id_Name_PK PRIMARY KEY(BNK_Id,BNK_Name)
When it allows null values in it.
thanks in advance

The Best Answer

Advertisement
Are you sure that your instructor was not talking about unique keys? As Solomon said, a primary key always implies not null on all of the columns of the PK. However a unique key does not automatically imply not null, and can have nulls in a column as long as the values in the populated columns are unique.
SQL> create table test (
  2     id number,
  3     pid number,
  4     descr varchar2(10));
Table created.
SQL> alter table test add constraint test_unq
  2     unique (id, pid);
Table altered.
SQL> insert into test values (1, null, 'desc1');
1 row created.
SQL> insert into test values (2, null, 'desc2');
1 row created.
SQL> insert into test values (2, null, 'fail1');
insert into test values (2, null, 'fail1')
ERROR at line 1:
ORA-00001: unique constraint (OPS$ORACLE.TEST_UNQ) violatedJohn
  • In which case composite primary key allows NULL values in it Update:10-11

    Hi to all In what case composite primary key allows nulls in it. Let us suppose, I created a composite primary key with 2 attributes. CREATE TABLE sample BNK_Id NUMBER(6), BNK_Name VARCHAR2(20), CONSTRAINT BNK_Id_Name_PK PRIMARY KEY(BNK_Id,BNK_Name)

  • Null in Composite Primary Key and "Primary keys must not contain null" Update:10-11

    Hello all. I'm a newbie concerning to JPA/EJB3, but I was wondering if toplinks doesn't support composite primary keys with null in some field (something perfectly right in any RDBMS). I used JDeveloper (I'm using Oracle 10g database and JDeveloper 1

  • Null value in Composite Primary key Update:10-11

    Hi, I have a requirement where I need to identify each record based on 4 columns. I though that I could achieve the same by imposing a composite primary key based on all the 4 columns. But any one of the column can be null at anytime. Can I still imp

  • Can a composite primary key column be null Update:11-30

    Hi All, It will be a silly question but still I would like to ask can a composite primary key column be null? Thanks, Rafi.Rafi, Why you think it would be allowed? SQL> drop table test purge; drop table test purge ERROR at line 1: ORA-00942: table or

  • Update enrolled table which has 6 composite primary key Update:11-30

    Hi Everyone, I am trying to update a grade column in table called enrolled which has 6 composite primary key column including SID, TERMYEAR, FACCODE, DEPCODE, COURSENO, SECNO and 2 extra column including GRADE, IDD all of them are of type VARCHAR2 as

  • Composite Primary Key Error Update:10-11

    I am using Sun One App Server PE8. I have a class with a composite primary key field. When I place the following method in my Home interface: public MyEjb findByPrimaryKey(MyEjbPrimaryKey pk) throws FinderException, RemoteException;I get the followin

  • Urgent - ESB: DB Adapter with composite primary keys no returning any data Update:11-30

    I have a DB Adapter in the ESB that inserts/updates/selects data to/from a table with 2 columns as primary keys, but table has several columns. 1. Initially, the db table had constraints for the composite primary key, The DB adapter had valid data co

  • Creation of CMP bean for a Composite Primary key???? Update:11-30

    Hi i am having a composite primary keys in one of my table in the database. I am trying to create a new entity bean for this table but i don't know how to create one in case when there is a composite primary key for a table. Can anybody let me know i

  • How to persist an entity with Composite primary key Update:11-30

    Problem Statement:- Entity A have many to one relation with Entity C Entity B have many to one relation with Entity C Entity C have a composite primary key of (Entity A PK & Entity B PK) A --< C B --< C the entites are automatic generated by Dal

  • Deployment Tool Problem (J2EE -Composite primary Key Class) Update:11-30

    Hi !! e.g. I have an entiybean which has composite primary key class. So while deploying in J2EE tool u need to specify the Primary key class and the primary key field. well in case of a composite primary key class(if u have more than one field)...ho