Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Nov 17th, 2018 66 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. -- a. modify the type of a column;
  2. -- b. add / remove a column;
  3. -- c. add / remove a DEFAULT constraint;
  4. -- d. add / remove a primary key;
  5. -- e. add / remove a candidate key;
  6. -- f. add / remove a foreign key;
  7. -- g. create / remove a table.
  8.  
  9.  
  10. DROP PROC IF EXISTS uspModifyColumnType
  11. GO
  12.  
  13. CREATE PROC uspModifyColumnType
  14. @table VARCHAR(30),
  15. @column VARCHAR(30),
  16. @desiredDataType VARCHAR(30)
  17. AS
  18.     DECLARE @statement NVARCHAR(4000)
  19.     DECLARE @params NVARCHAR(4000)
  20.     SELECT @statement = 'ALTER TABLE ' + QUOTENAME(@table) + ' ALTER COLUMN ' + QUOTENAME(@column) + QUOTENAME(@desiredDataType)
  21.     SELECT @params = N' @table VARCHAR(30),' +
  22.                      N' @column VARCHAR(30),' +
  23.                      N' @desiredDataType VARCHAR(30)'
  24.     PRINT @statement
  25.     PRINT @params
  26.     EXECUTE sp_executesql @statement, @params, @table = @table, @column = @column, @desiredDataType = @desiredDataType
  27. GO
  28.  
  29. EXEC uspModifyColumnType 'Products', 'price', 'INT'
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top