Answer 1:
A table column with this constraint is called the key column for the table. This constraint helps the table to make sure that the value is not repeated and also that there are no null entries. This column does not allow null values and duplicate values. You can try inserting values to violate these conditions and see what happens. A table can have only one Primary key. Multiple columns can participate on the primary key.
Answer 2:
A primary key is a combination of fields which uniquely specify a row. This is a special kind of unique key, and it has implicit NOT NULL constraint. It means, Primary key values cannot be NULL.
A primary key in a database is a unique identifier for a record in a table. It serves two main purposes:
Uniqueness: A primary key ensures that each record in a table is uniquely identifiable. No two records in the table can have the same value for the primary key column(s). This uniqueness helps prevent data duplication and maintains data integrity.
Referential Integrity: A primary key is often used as a reference point for establishing relationships between tables in a relational database. It is used as a foreign key in related tables to create associations and maintain referential integrity. This ensures that data remains consistent across related tables.
Key characteristics of a primary key:
Example: Suppose you have a "Customers" table. You might designate the "CustomerID" column as the primary key. This ensures that each customer has a unique identifier, and you can use this identifier to establish relationships with other tables (e.g., orders, transactions) while maintaining data integrity.
SQL Syntax for creating a primary key:
CREATE TABLE Customers ( CustomerID INT PRIMARY KEY, FirstName VARCHAR(50), LastName VARCHAR(50), Email VARCHAR(100) );
In this example, the "CustomerID" column is defined as the primary key of the "Customers" table.
First read the answer fully, then try to explain it in your own words. After that, open a few related questions and compare the concepts. This method helps you remember the topic for a longer time and improves exam preparation.