Search code examples
sql-server-2005

Check whether a table contains rows or not sql server 2005


How to Check whether a table contains rows or not sql server 2005?


Solution

  • For what purpose?

    • Quickest for an IF would be IF EXISTS (SELECT * FROM Table)...
    • For a result set, SELECT TOP 1 1 FROM Table returns either zero or one rows
    • For exactly one row with a count (0 or non-zero), SELECT COUNT(*) FROM Table