What is a primary key? What is a secondary key? What is a foreign key? What is the difference between each of them? Where are they used? What is a join? What are the different kinds of joins? Explain how they work? Can you differentiate between GROUP BY and ORDER BY?
Different types of SQL keys and their usage
A key is generally a single or combination of multiple fieldsÂ
in a database table. Their main use is to retrieve theÂ
required data from the table.The main types are-
1.Candidate key- A candidate is a combination of various columns
in a table. A number of candidate keys are allowed in a table.
2. Super key- A super key is a combination of various keys.
3. Primary key- It's used to distinguish between various columns
of a database table. A single key can be used a primary key.Null
values and duplication are not allowed in a primary key.
Â
4. Alternate key -An alternate works as a primary key. It's a
candidate key but not a primary key.
5. Composite key- A combination of primary key and candidate key isÂ
termed as a composite key.
6. Unique key- It is a primary key which accepts only one NULL
value.
7. Foreign key- It is a primary key which contains NULL andÂ
duplicate values.
Hope it helps you.Â