0

When I execute

exec sp_columns TABLE_NAME

it returns many columns, I need to display specific columns only and add a description column as well.

Is there anyway for me to customize the table to do this?

I am using SQL Server 2012 Management Studio

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
hhdesign
  • 7
  • 1
  • 2
  • possible duplicate of [How to add a comment to an existing table column in SQL Server?](http://stackoverflow.com/questions/9018518/how-to-add-a-comment-to-an-existing-table-column-in-sql-server) – void Sep 28 '15 at 01:00

3 Answers3

0

With SSMS you can use the table designer to add columns fairly easily. In the server browser, find your table, right click, and "Design."

Andrew Shirley
  • 407
  • 2
  • 10
  • Would that be the option Design query in editor? That is the only thing that says design when I right click. thanks alot for your help! – hhdesign Sep 27 '15 at 21:04
0
--Check if column does not exists, if yes than add.
IF NOT EXISTS (
        SELECT *
        FROM sys.columns
        WHERE [name] = N'Column_Name'
            AND [object_id] = OBJECT_ID(N'Table_Name')
        )
BEGIN
    ALTER TABLE Table_Name ADD Column_Name Type;
END

-- Similarly for removing column
--Check if column does exists, if yes than add.
IF EXISTS (
        SELECT *
        FROM sys.columns
        WHERE [name] = N'Column_Name'
            AND [object_id] = OBJECT_ID(N'Table_Name')
        )
BEGIN
    ALTER TABLE Table_Name Remove Column_Name;
END
GO
0

select column_name, table_name from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME like '%table name%' and column_name in ( 'column1', 'column2' )

Siva
  • 21
  • 3