Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,154,739 members, 7,824,102 topics. Date: Friday, 10 May 2024 at 11:04 PM

I Am A Learner, Please What Are Primary Keys And How Do I Create Then? - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / I Am A Learner, Please What Are Primary Keys And How Do I Create Then? (717 Views)

I Doubt If You All Know The Name Of Some Of The Keys On An English Keyboard! / How Do I Create A Licenses Key For My Application / How Do I Create A Desktop Shortcut For My Application? (2) (3) (4)

(1) (Reply) (Go Down)

I Am A Learner, Please What Are Primary Keys And How Do I Create Then? by DejiAdewumi: 8:01am On Oct 02, 2013
Kindly help with this problem
Re: I Am A Learner, Please What Are Primary Keys And How Do I Create Then? by Javanian: 8:11am On Oct 02, 2013
Primary keys in a database? undecided
Re: I Am A Learner, Please What Are Primary Keys And How Do I Create Then? by sparko1(m): 9:09am On Oct 02, 2013
Is it in Access or MySql?
Re: I Am A Learner, Please What Are Primary Keys And How Do I Create Then? by adewasco2k(m): 12:27pm On Oct 02, 2013
On a table let's say users, you have may be userid, name, email, password

Primary key and unique key are more like same


You can set the user I'd to auto increment then set it as a primary key so two users can not have the same userid, it is just a unique way of identify a row in a table.
You can also set the username or email to be the primary key, so no user can have the same unsername.

When creating a table you just add:

Primary key (email)

Or if you already have the table, just alter it

ALTER TABLE users ADD PRIMARY KEY (email)

You may also want to know what secondary keys are.

1 Like

Re: I Am A Learner, Please What Are Primary Keys And How Do I Create Then? by adewasco2k(m): 12:31pm On Oct 02, 2013
Sorry, if you set for example user id to auto increment, automatically it is a unique key because nobody can have the same id.

But in a place for example a student database system where you want to give every student an enroll number, that must be set as primary key.

1 Like

Re: I Am A Learner, Please What Are Primary Keys And How Do I Create Then? by DejiAdewumi: 7:13am On Oct 03, 2013
Thanks so much for your concern. I got it. God bless u.
Re: I Am A Learner, Please What Are Primary Keys And How Do I Create Then? by Nobody: 7:13am On Oct 03, 2013
Deji Adewumi: Kindly help with this problem

Primary keys are fields/attributes that you use to uniquely identify an item.

Let's say, for example, you have a database that manages student information in a particular school. Each student could have different fields/attributes like first name, last name, surname, date of birth etc... Chances are that 2 students might end up bearing identical names and this could cause problems later on.

To avert such a scenario, a new attribute could be introduced - say a registration number or id number. This attribute/field will uniquely identify each student so that even students with identical names end up having a unique identifier.




To the second part of your question, what database are you using?

1 Like

(1) (Reply)

What Are Your Challenges Learning How To Program? / Please What Should I Do? I'm Getting Error Message When Trying To Compile Java! / Python The Myth

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 9
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.