SQL Template - Add Column


/ Published in: SQL
Save to your folder(s)

My Add Column Varchar.sql
This template adds a new varchar column to the table.


Copy this code and paste it in your HTML
  1. --==========================================================================
  2. -- Add varchar column template
  3. --
  4. -- This template adds a new varchar column to the table.
  5. --
  6. -- Use the Specify Values for Template Parameters
  7. -- command (Ctrl-Shift-M) to fill in the parameter
  8. -- values below.
  9. --==========================================================================
  10.  
  11. PRINT 'ALTER TABLE <schema_name, sysname, dbo>.<table_name, sysname, sample_table> ADD <new_column_name, sysname, sample_column> <new_column_datatype,, varchar(50)> <new_column_nullability,, NULL>'
  12. GO
  13. IF NOT EXISTS (SELECT * FROM dbo.syscolumns WHERE id = OBJECT_ID(N'<schema_name, sysname, dbo>.<table_name, sysname, sample_table>') AND name = N'<new_column_name, sysname, sample_column>')
  14. BEGIN
  15. ALTER TABLE <schema_name, sysname, dbo>.<TABLE_NAME, sysname, sample_table> ADD
  16. <new_column_name, sysname, sample_column> <new_column_datatype,, VARCHAR(50)> <new_column_nullability,, NULL>
  17. END
  18. GO

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.