Edit 3 : I was following Head First SQL , where it was said we can use keywords such as First
, Second
etc etc. I stand clarified by @StanMcgeek that one can only use First
, Last
and After
.
Before the reader gets friendly with the down-vote , I'd like to mention that
- I know column Re-arrangement is generally just an aesthetic issue.
- I'm doing it for learning purpose only
That being said , this is what i was trying to do:
hooptie
is a table , with some values , i'd like to rename it to car_table
and add some more columns to it. Below is the renamed hooptie
, and my attempts at adding and re-arranging the order of a few columns. The output is -tee
'd into a text file. text is easier to post than screenshots :)
--------------
select * from car_table
--------------
+--------+------+----------+----------+-----------+
| color | year | make | mo | howmuch |
+--------+------+----------+----------+-----------+
| silver | 1998 | Porsche | Boxter | 17992.539 |
| NULL | 2000 | Jaguar | XJ | 15995.000 |
| red | 2002 | Cadillac | Escalade | 40215.898 |
+--------+------+----------+----------+-----------+
--------------
alter table car_table
add column car_id int not null auto_increment first,
add column VIN varchar(16) second,
modify make varchar(20) third,
change mo model varchar(20) fourth,
modify color varchar(20) fifth,
modify year varchar(4) sixth,
change howmuch price decimal(7,2) last
--------------
After doing the above alterations , i do another select * from car_table
, but the table has remained the same. I suppose that randomly saying first
, second
, third
etc dont really cut it . Can anyone explain what's going on here ?
Edit1: error message that i'm getting says :
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'second,
I dont like mysql error messages too much .. they seem a little vague to me.
Edit2: I have used keywords like After
, and i know it works. I wanted to understand how first
,second
etc keys work.
p.s : I'm following the Head-First-SQL book , the data is taken from there too.