00:40 Create table query
01:02 Adding Primary Key
02:41 Adding Primary Key to existing table
03:25 Dropping Primary Key
05:00 Adding data with Primary Key
08:26 Using IGNORE adding data
10:35 Using two columns as Primary Key
11:11 Example with Difference between Primary Key and Unique Key
We can add Primary Key to existing table by using ALTER table command
Primary Key will not allow duplicate data and at the same time Null data is also not allowed. WE can use two columns as primary key.
We can remove Primary Key by using DROP command
ALTER TABLE student DROP PRIMARY KEY
The main difference between Primary Key and unique key is here
Table can have one Primary key but can have multiple Unique Key
Null data is not allowed in Primary Key but Unique Key can have Null data
Indexing is clustered in Primary Key and it is non clustered in Unique Key
We can list the structure with Keys of a table by using SHOW
SHOW CREATE TABLE student
While adding data to Primary Key column in case of error due to validation no data is inserted. To ignore the error and to insert the valid data we can use IGNORE command.
INSERT IGNORE INTO `my_tutorial`.`student`
(`id` ,`name` ,`class` ,`mark` ,`gender`)
VALUES ('10', 'test name', 'Four', '55', 'male'),
('36', 'test name 2', 'Four', '57', 'male');
Source code is available here
https://www.plus2net.com/sql_tutorial...
#PrimaryKey #UniqueKey #PrimaryKeyUniqueKey #TableConstraints #QueryAddingKey #DeletingPrimalyKey #DropPrimaryKey #AddPrimaryKey #AlterTable #AddKey #AddingConstraints