Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Drop Column

Author  Topic 

yellowman
Starting Member

25 Posts

Posted - 2004-12-29 : 08:33:04
I am trying to drop a column from a table using the following syntax:

ALTER TABLE daily_reading DROP COLUMN MyPK
go


...but I get an error everytime I try to run it:

Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'MyPK'.


Where's the syntax error?

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2004-12-29 : 09:06:06
Is MyPK the column name?
Go to Top of Page

yellowman
Starting Member

25 Posts

Posted - 2004-12-29 : 09:21:16
yes it is. This is how it was created...

Alter table dup_authors add MyPK int NULL
go

Then the column was filled with a bunch of sequential numbers.
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2004-12-29 : 09:34:44
It's giving a syntax error suggesting there is some other character there or you didn't execute the whole statement.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

yellowman
Starting Member

25 Posts

Posted - 2004-12-29 : 11:01:16
Is the syntax correct on the above statement then? I don't see any other stray characters there unless they are invisible
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2004-12-29 : 11:32:01
does "go" have to be capitalized? (I have no idea, just guessing)

- Jeff
Go to Top of Page

yellowman
Starting Member

25 Posts

Posted - 2004-12-29 : 11:38:21
SQL Server isn't case sensitive like Oracle is, so no 'go' does not need to be capitalized. I still tried it though just to make sure
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2004-12-29 : 12:09:37
Try this

create table #a (i int, j int)
alter table #a drop column j


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

yellowman
Starting Member

25 Posts

Posted - 2004-12-29 : 12:12:05
This is what I get when I run the above script...

Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'j'.
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2004-12-29 : 12:57:49
Which version are you running?
If 2000 are you in compatibility mode

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

yellowman
Starting Member

25 Posts

Posted - 2004-12-29 : 14:02:37
Ha....
That was it. I was running with a compatibility of 65. Thanks for all of your help.
Go to Top of Page
   

- Advertisement -