Removing a column from a table using SQL

Results 1 to 3 of 3

Thread: Removing a column from a table using SQL

  1. #1
    Pipey Guest

    Default Removing a column from a table using SQL

    I&#039m trying to remove the column &#039ID&#039 from table &#039Organisation&#039 by executing an SQL command. I&#039m sure I&#039m following the correct SQL syntax for this. But I get the error &#039Error: Line 1: Incorrect syntax near &#039ID&#039<BR>Am I being totally stupid? Can anyone tell me if I&#039m using the right SQL syntax?<BR><BR> Dim objConn As ADODB.Connection<BR> Dim strSQL<BR> Dim strConn<BR> <BR> strConn = "Provider=SQLOLEDB; Data Source=MyServer; Initial Catalog=MyDb; User Id=sa; Password=;"<BR><BR> Set objConn = New ADODB.Connection<BR> objConn.Open strConn<BR> <BR> strSQL = "ALTER TABLE Organisation DROP COLUMN ID"<BR> objConn.Execute <BR> <BR> objConn.Close

  2. #2
    Shawn Clabough Guest

    Default RE: Removing a column from a table using SQL

    What happens when you try "ALTER TABLE Organisation DROP ID"<BR>

  3. #3
    Jeppe Salvesen Guest

    Default RE: Removing a column from a table using SQL

    I&#039m working on the same problem. I&#039ve got a few stale columns around in my forum, so I&#039m trying to remove those. However, MS SQL Server is not very cooperative:<BR><BR>Query:<BR> ALTER TABLE Forum_Messages DROP UserName<BR>Answer:<BR> Msg 3731, Level 16, State 0<BR> &#039UserName&#039 is not a valid object.<BR> Msg 3727, Level 16, State 0<BR> Unable to drop constraint. See previous errors.<BR><BR>Query:<BR> ALTER TABLE Forum_Messages DROP COLUMN UserName<BR>Answer:<BR> Msg 170, Level 15, State 1<BR> Line 1: Incorrect syntax near &#039UserName&#039.<BR><BR>From this, I tend to conclude that dropping fields in a table is not supported by Microsoft SQL Server 6.5. A spank goes out to Bill Gates. I hope he doesn&#039t like it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •