Search code examples
sql-serveralter

Cannot add column in SQL Server ( Incorrect syntax near 'string'.)


I want to add a column to my table in SQL Server. I believe the syntax is correct but I'm still getting this error:

example image


Solution

  • Your syntax is totally wrong - you cannot have an ALTER TABLE which is followed by both a DROP COLUMN .... and an ADD afterwards - you need to repeat the ALTER TABLE part:

    ALTER TABLE sample_searches
    DROP COLUMN ...... ;
    
    ALTER TABLE sample_searches
    ADD search_date DATE NULL, Time INT NULL;
    

    Also, since you have SELECT * FROM taas..sample_searches, you might need to first switch to the taas database before you can run these statements....