Monday, February 13, 2012

Add a column to a table.

I know this should be stupidly easy to do but I'm pulling my hair out trying to figure out how to write a SQL query to add a column to an existing table with SQL Server 2005. Every single reference I've found says to use "ALTER TABLE", yet when I do SQL says...

"The ALTER TABLE SQL construct or statement is not supported."

So how the $%^$ am I supposed to add a column? I've wasted about 3 hours on this simple task and it's really starting to piss me off.

Hi,

from where are you firing your query ? iring the query from the query ane of the Managment studio just works fine for me with the following script.

USE ADVENTUREWORKS

GO

DROP TABLE SomeTable

GO

CREATE TABLE SomeTable

(

SomeColumn INT

)

ALTER TABLE SomeTable

ADD SomeCOlumn2 INT

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

|||

That's where it gives me the error. A simple statement like this does it.

ALTER TABLE History ADD Mar06 int

Even if I just do this query it says it too.

ALTER TABLE History

In Management Studio it pops up the error message and gives me a choice of clicking "Continue" or "Cancel". If I click "Contine" it does the query and it works, but if I do the exact same query from a PHP script it doesn't work, even through the rest of the queries in the script work just fine. I don't get it at all. The full query that I want to run is...
ALTER TABLE History ADD Mar06 int DEFAULT 0 NOT NULL
Edit: Okay, I finally figured it out and it seems the user I was logged in as didn't have ALTER permissions. That error message was making me think it was something wrong with my query so that's what I was focused on fixing. It looks to be working fine now, though that error message still pops up.

No comments:

Post a Comment