Category: MySQL

MySQL Drop index

MySQL Drop index Drop index from MySQL table using alter table syntax. MySQL Drop index syntax ALTER TABLE table_name DROP INDEX index_name; Drop index example ALTER TABLE `books` DROP INDEX idx_product_id; Output table `books` altered....

MySQL Add index

MySQL Add index Add index on MySQL table using alter table syntax. MySQL Add index syntax ALTER TABLE table_name ADD INDEX index_name(column_name); Add index example ALTER TABLE `books` ADD INDEX idx_product_id (product_id); Output table `books` altered....

MySQL Drop foreign key

MySQL Drop foreign key Drop foreign key from MySQL table using alter table syntax. MySQL Drop foreign key syntax ALTER TABLE table_name DROP FOREIGN KEY foreign_key_name; Drop foreign key example ALTER TABLE `books` DROP FOREIGN KEY fk_product_id; ALTER TABLE `books` DROP...

MySQL Add constraint foreign key

MySQL Add constraint foreign key Add foreign key to MySQL table using alter table syntax and add constraint keyword. MySQL Add constraint foreign key syntax ALTER TABLE table_nameB ADD CONSTRAINT constraint_name FOREIGN KEY (column_name) REFERENCES table_nameA (column_name); Add constraint foreign key...

MySQL Add primary key

MySQL Add primary key Add primary key to MySQL table using alter table syntax and primary key keyword. MySQL Add primary key syntax ALTER TABLE table_name ADD PRIMARY KEY (column_name); Add primary key example ALTER TABLE `books` ADD PRIMARY KEY (id);...