This just goes to show the power and value of the #sqlhelp hashtag on twitter and, also, the SQL Server Community slack channels too. #Drop column mysql updateI wasn’t able to locate a blog or a twitter account for Vassilis but would be happy to update in the future. He followed up by sharing the question with the MVP list where Vassilis Papadimos replied back and provided the correct syntax which you will see in the solution below. As you can see from the above output that the column productdate does not exist anymore. ALTER TABLE Products DROP COLUMN productdate Here is the output of the SELECT statement after the above statement completes. It turns out this was heading down the right path as it would be a per-column option and the solution is just ahead, but first… SQL Communityįortunately for me the SQL Community is, without a doubt, one of the best technical communities out there and shortly after I posted a call for help on Twitter using the #sqlhelp hashtag, Robert Davis ( b| t) replied back and we tested and came to the conclusion that it looked like it wouldn’t work for multiple columns. 1) Dropping a single column In this example, we will drop the productdate column from the Products table. ALTER TABLE #TestĭROP COLUMN IF EXISTS col2, IF EXISTS col3 I tried a couple of variations: ALTER TABLE #Test You can see it being used above for the temp table. But first I had to track down the correct syntax.įirst let’s set up a demo table: DROP TABLE IF EXISTS #Test “This will work nicely!” I thought to myself. Since this was on SQL Server 2016 the DROP IF EXISTS syntax sprang to mind. I needed to drop a fixed set of columns should they exist in my table. This post is half “how to” and half community bragging.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |