Last answered:

20 Apr 2020

Posted on:

19 Apr 2020

0

Remove Column record does not work with Change Statement

Hi, For Intro to Join exercise, when I typed in the following codes, the dept_no still shows . could you help to figure out what is going on there? Thank you.   ALTER TABLE departments_dup CHANGE COLUMN dept_no dept_no CHAR(4) NULL; Thanks, Jo Zhou
1 answers ( 0 marked as helpful)
Instructor
Posted on:

20 Apr 2020

0

Hi Jo!
Thanks for reaching out.
This is a very interesting question!
Basically, this modification doesn't turn the dept_no into a Unique Key. Instead, it adds NULL as a default value. Moreover, it doesn't affect the records that have been inserted so far in the table.
That's why if you executed again the following query, for instance:

INSERT INTO departments_dup
(
dept_no,
dept_name
)
SELECT 
*
FROM 
departments;

you'll manage to insert all for records with all department numbers available. However, if you only try to insert a record containing a value for the department name, then the value in the dept_no field will be null.

INSERT INTO departments_dup (dept_name) VALUES ('Finance');


Hope this helps.
Best,
Martin

Submit an answer