Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a new column 1

Status
Not open for further replies.

kupe

Technical User
Sep 23, 2002
376
To ADD a new column I can say that I want it AFTER some named column.

But what if I want this new column to be the first, please, Experts?
 
You could use:
[tt]
ALTER TABLE tbl1
ADD newcol INT FIRST
[/tt]
 
Many thanks, Tony. You probably don't have time to answer this, but why 'INT' there please?
 
No reason, I was just using it as an example. You would replace the INT with whatever data type you were using, CHAR(20) for example.
 
All clear now. Many thanks.
 
Hi Tony

Put to the test several times last night, it worked once, many thanks. After that, I wasn't able to add a first column on other tables. I kept being dismissed with "Error 1062: Duplicate entry '0' for key 1".

Be grateful to know what it means. Cheers

 
That message would appear if you were trying to add or update a record where one of the fields has a unique index and the value of that field is already in the index.

For example, if the table has a primary key on the "id" field, and there is already a record in the table with an "id" value of 123, and you try to add another record with ad "id" value of 123, you would be rudely and rightly rebuffed. Same thing would happen if you tried to change the value of the "id" field in another record to 123.
 
All noted, Tony. But I was trying to make sure that I didn't duplicate anything. But as it worked once, I can see you've put me on the right track. I'll take a copy of the above with me, and ensure I keep everything strictly correct tonight. Many thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top