The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Ask
Anybody can ask a question
Answer
Anybody can answer
Vote
The best answers are voted up and moderated by our team

Remove Column record does not work with Change Statement

Remove Column record does not work with Change Statement

Super Learner
0
Votes
1
Answer

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 Answer

365 Team
0
Votes

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