WHAT EXACTLY IS HAPPENING WHEN WE MAKE A FIELD A PRIMARY KEY

Anupam Mishra

Total Post:135

Points:949
Posted by  Anupam Mishra
 921  View(s)
Ratings:
Rate this:
Hi Everyone,
I want know, when we make any field a primary key in a table then what is happening internally in database.
Please can anyone give me a solution.
Thank you.

  1. Manoj Bhatt

    Post:154

    Points:1086
    Re: What exactly is happening when we make a field a primary key

    Primary Key:  Primary key is a key that is selected as the primary key. Only one key within an entity is selected to be the primary key. This is the key that is allowed to migrate to other entities to define the relationships that exist among the entities. When the data model is instantiated into a physical database, it is the key that the system uses the most when accessing the table, or joining the tables together when selecting data.[WIKI]  When we creating a primary key in a table such as below:

    SQL> CREATE TABLE STUDENTS (  
    ID INT                           NOT NULL,  
    NAME VARCHAR (20) NOT NULL,  
    AGE INT    NOT NULL,  
    ADDRESS CHAR (25),  
    PRIMARY KEY (ID)  
    );  
    Here ID is a primary key. It will internally  create a clustered index in a database.
    A clustered index will be created for that specific field.A clustered index sorts and stores the data rows in the table based on the index key values. Therefore only one clustered index can be created on each table because the data rows themselves can only be sorted in one order. A clustered index sorts and stores the data rows in the table based on the index key values. Therefore only one clustered index can be created on each table because the data rows        
    themselves can only be sorted in one order.
     To create a different clustered index on the same table, change the Create as Clustered property setting on the existing clustered index before creating the second index.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!