SQL query to add primary key

SQL query to add primary key

In this article, we will figure out how to compose a SQL Query to add primary key to a section?

Primary key: This key is utilized to characterize the uniqueness of segment as there consistently ought to be a one of a kind line of information for this segment.

This is imperative to have one primary key. A primary key is a property of a segment, which characterizes that the segment will have one of a kind values.

The Simple yet incredible example of this idea is Roll Number of an understudy. The Roll Number consistently contains extraordinary value unfailingly.

For what reason is primary key so significant? All things considered, there are various responses to it, yet what, one of the less talked about contention is that primary key assistance to interface diverse table together without any problem.

This gives us so much force that we ought not stress over the space, as at whatever point we have to utilize the record all we will do is utilize the primary key.

Table (worker) having three fields and four information in it,

    Id		Name		Address

    100		Aman		Mumbai
    200		Arun		Pune
    300		Karan		Delhi
    400		Aman		Mumbai

As should be obvious the above table have three sections, they didn’t characterize as a primary key however assume we have to include a primary key segment id the we should simply, utilize adjust table and alter the segment to include a primary key with the name of the segment as the parameter in it.

Query 1:

ALTER TABLE employee 
MODIFY COLUMN 'id' INT(10) 
UNSIGNED NOT NULL AUTO_INCREMENT, ADD PRIMARY KEY ('id');

Output:

SQL query to add primary key

DURGESH

I Love python, so I like machine learning a Lot and on the other hand, I like building apps and fun games I post blogs on my website for Tech enthusiast to learn and Share Information With The World.

Leave a Reply

Your email address will not be published. Required fields are marked *

1 × four =

Recent Content