How can I tell if a column for a table already exists?

A. There are two ways (with SQL 7) :-

IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '<tbl>' AND COLUMN_NAME = '<col>')

or

if columnproperty (object_id('<tbl>'), '<col>', 'AllowsNull') IS NOT NULL


Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish