How to change column order in a table using sql query in sql server 2005?

You cannot. The column order is just a “cosmetic” thing we humans care about – to SQL Server, it’s almost always absolutely irrelevant. What SQL Server Management Studio does in the background when you change column order there is recreating the table from scratch with a new CREATE TABLE command, copying over the data from … Read more

How to detect if a stored procedure already exists

If you DROP and CREATE the procedure, you will loose the security settings. This might annoy your DBA or break your application altogether. What I do is create a trivial stored procedure if it doesn’t exist yet. After that, you can ALTER the stored procedure to your liking. IF object_id(‘YourSp’) IS NULL EXEC (‘create procedure … Read more