MySQL ALTER Command

1.Create Table with CTAS Command
We will use the CREATE TABLE AS SELECT command to create a new table based on an existed table
Example:
CREATE TABLE baseora.chemical AS SELECT * FROM peps.chemical;
CREATE TABLE baseora.used AS SELECT * FROM peps.used;
CREATE TABLE baseora.job AS SELECT * FROM peps.job;

2.ALTER command to create Primary Key for Table
ALTER TABLE truck
ADD CONSTRAINT pk_truck PRIMARY KEY (truck_num);

3.ALTER command to create Foreign Key for Table
ALTER TABLE drive
ADD CONSTRAINT fk_truckdrive
FOREIGN KEY (truck_num) REFERENCES truck(truck_num);

4.ALTER command to create CHECK Constrain for Table
ALTER TABLE chemical
ADD CONSTRAINT chk_concentration CHECK (chem_concentration>0 AND chem_concentration<=1);

Add Comment