In: Computer Science
How do I start to code in mysql to Alter table to modify column
remove not null constraint
First drop the foreign key associated with
Drop the column
Add the column back with new definition
Add the foreign key back
This Is what I wrote so far
alter table employees modify column repotsTo remove null:
SELECT DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'employees' AND COLUMN_NAME = 'reportsTo'
ALTER TABLE `employees` DROP FOREIGN KEY `fk`;
ALTER TABLE employees ADD CONSTRAINT fk FOREIGN KEY (reportsTo) REFERENCES <Table Name>(<column_name>);