Thursday, 6 July 2017

Define non-prime attribute

Define non-prime attribute, What is non-key attribute, Non-key attribute examples, Why they are non-key attributes?

Non-prime (Non-key) attribute

Primary key is an attribute or set of attributes that are chosen to uniquely identify any records in a table. The values of a primary key cannot be duplicated. On the other hand, non-prime (non-key) attributes are the attributes other than the primary key attributes. They can store a value any many times.

For example, let us consider the following schemas; (primary keys underlined)

STUDENT (RegNo, Name, Date_of_Birth, Address)
COURSE_REGISTRATION (RegNo, Course_No, No_of_Credits, Venue)

In the schema STUDENT, the attribute RegNo is the primary key (prime attribute). All the other attributes are non-prime attributes.

In schema COURSE_REGISTRATION, the attributes RegNo and Course_No together forms the primary key. All the other attributes are non-prime attributes. In this case, individually RegNo is one prime attribute and Course_No is another prime attribute.

Why they are called as non-key attributes?

They are non-key attributes because they cannot uniquely identify any records of the table.
For example, look at the following queries;
SELECT * FROM Student WHERE RegNo = ‘12345’;
SELECT * FROM Student WHERE Name = ‘Kumar’;
Here, RegNo is the primary key of Student table, so the first query will return zero or one record (if 12345 is a register number). On the other hand, Name is not a primary key. Hence, the second query will return all the records that stored ‘Kumar’ as name.


No comments:

Post a Comment

SQL exercises for beginners one

SQL Exercises for Beginners / Simple SQL Exercises with Answers / Solved SQL exercises / SQL solved exercises with simple conditions / So...