Adding a new column to a MS SQL Table safely

April 8th, 2008 admin Posted in sql |

How could we check if a column exists and add it to a table if it doesn't? Very easily!

 
IF NOT EXISTS
	(SELECT * FROM syscolumns
	WHERE id = OBJECT_ID(N'[MyTable]') AND name = 'MyColumn')
             ALTER TABLE dbo.MyTable ADD MyColumn INT

Enjoy!

9 Responses to “Adding a new column to a MS SQL Table safely”

  1. Nice little tip.

  2. < blockquote >< a href=”http://pillspot.org/”>Pillspot.org. Canadian Health&Care.Best quality drugs.Special Internet Prices.No prescription online pharmacy. High quality pills. Buy drugs online< /a >…

    Buy:Levitra.Tramadol.Viagra Professional.Cialis.VPXL.Cialis Super Active+.Cialis Soft Tabs.Viagra Super Active+.Maxaman.Viagra Super Force.Viagra.Viagra Soft Tabs.Cialis Professional.Soma.Super Active ED Pack.Zithromax.Propecia….

  3. < blockquote >< a href=”http://pillspot.org/”>Pillspot.org. Canadian Health&Care.Best quality drugs.Special Internet Prices.No prescription online pharmacy. Low price pills. Buy pills online< /a >…

    Buy:Prevacid.Synthroid.Human Growth Hormone.Zovirax.Accutane.Actos.Prednisolone.Nexium.Lumigan.Petcam (Metacam) Oral Suspension.Retin-A.Valtrex.Mega Hoodia.100% Pure Okinawan Coral Calcium.Zyban.Arimidex….

  4. 00a amp power/ http://ACEHARDWAREE.INFO/tag/QSC MX 10 : 00a amp power/…

    QSC…

Leave a Reply

You must be logged in to post a comment.