FAQ: Manipulation - Alter

This community-built FAQ covers the “Alter” exercise from the lesson “Manipulation”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development
Data Science

Learn SQL

FAQs on the exercise Alter

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

It would be good if the clause ‘ADD COLUMN’ is color blue as well. It appears white and tends to be confusing :smiley:

3 Likes

Honestly though. I don’t know any of the moderators aren’t helping clear this up. It doesn’t seem logical for ‘ADD COLUMN’ to stay white. I mean, it’s a clause/command right?

I agree - it should be depicted blue like all the other clauses.

Aaand it is blue now, May 2020 :smiley:

1 Like

Folks, can you actually query two different requests at the same time IRL? Like here we are asked to first ADD COLUMN and then run SELECT query, and we see results of both happening - is that also possible/common practice in real programs?

New question - I am wondering if ALTER TABLE can be used for any commands other than adding a new table?

  • If yes, what commands?
  • If no, then why do we also need to specify ADD COLUMN? Seems like a duplication of the command.
1 Like

Why are the select and from clauses included for this query? The alter clause references the celeb table and we are not selecting any data from that table so I do not understand the purpose. Thanks

ALTER TABLE celebs
ADD COLUMN twitter_handle TEXT;
SELECT * FROM celebs;

1 Like

Here both the
ALTER TABLE celebs
ADD COLUMN twitter_handle TEXT;

and
SELECT * FROM celebs;

are different statements.
The first one is for adding the column in the respective table name ‘celebs’, and the second statement is for fetching all the records in that table. You can notice after adding a new column, all the values for that respective column are NULL for pre-existing records.

:grinning:

After we hit RUN and move to the next exercise - where does SQL retrieve the table’s data (“celebs”)?
does it save “celebs” like cookies or something on our computer?
I mean, there is no table creating commands at the head of our code…so…how?

This query worked but strangely enough random characters seemed to disappear. Seems like an environmental issue.
the i, t, and n from twitter_handle.

image

I am really confused by the addition of SELECT * FROM celebs; under the

ALTER TABLE celebs
ADD COLUMN twitter_handle TEXT;

Would the first 2 lines add a column to the table but just not display it? That is, until someone queries twitter_handle?

Or would the first 2 lines do nothing?

Perhaps this might help.
Each of us are working in a programming environment that supports a SQL interpreter. This could be installed on your personal PC and accessed via the black command window.
But we are not using our own PC, we are using an instance of the environment that is connected to our Codecademy browser session. A SQL interpreter is running within this instance of the environment.
SQL statements can be sent to the interpreter in any order, but putting them in incorrect order may return goofy results. Like trying list all rows before creating a table.
SQL programs consist of statements; there is no practical limit to how many you can provide. Each statement is executed independently of the others before and after it. It’s up to you to write them in a way and sequence that produces rational results.
When you create anything in SQL, such as a table, row, variable, etc, it is saved in your Codecademy environment, ie out in the cloud, not on your PC.

1 Like

Curious if you can have a parameter for twitter_handle for both TEXT and INTEGER. What if someone’s username has a number?

I’m fairly certain that this should be fine, at least within SQLite, as it does not enforce types. It’s probably preferable to put single quotes around the number username to keep the type consistent though.

Does anyone know what would happen if you used ALTER TABLE and ADD COLUMN to add a column with the NOT NULL constraint? I tried it in the codecademy environment and it did not return the table back.

My issue with this whole chapter is that all of the answers are already printed in the instructions. I could technically copy and paste my way through the entire chapter. I learn best when I have a chance to figure it out myself.