Alter in myssql code example

Example 1: add column in sql

ALTER TABLE `fb_banners`
ADD `city_id` BIGINT(20) UNSIGNED NULL DEFAULT NULL AFTER `BannerID`,
ADD INDEX `Foreign_city_id_banners` (`city_id`) USING BTREE,
ADD CONSTRAINT `Foreign_city_id_banners` FOREIGN KEY (`city_id`) REFERENCES `foodsafari`.`fb_cities` (`id`) ON UPDATE CASCADE ON DELETE CASCADE;

Example 2: sql alter table

Adds, deletes or edits columns in a table. It can also be used to add and
delete constraints in a table, as per the above.
Example: Adds a new boolean column called ‘approved’ to a table named
‘deals’.
ALTER TABLE deals
ADD approved boolean;
Example 2: Deletes the ‘approved’ column from the ‘deals’ table
ALTER TABLE deals
DROP COLUMN approved;

Tags:

Sql Example