The best way to use a PRIMARY KEY or UNIQUE Index on a table with appropriate fields to stop duplicate records. I will provide you the example, that will contains no such index or primary key, so it would allow duplicate records for first_name and last_name
Code:
CREATE TABLE person_tbl
(
first_name CHAR(20),
last_name CHAR(20),
sex CHAR(10)
);
To prevent multiple records with the same first and last name values from being created in this table,we will add a PRIMARY KEY to its definition. This is necessary to declare the indexed columns to be NOT NULL, because a PRIMARY KEY does not allow NULL values, you may see this as I will change the above example to its primary Key.
Code:
CREATE TABLE person_tbl
(
first_name CHAR(20) NOT NULL,
last_name CHAR(20) NOT NULL,
sex CHAR(10)
PRIMARY KEY (last_name, first_name)
);
Bookmarks