Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
albaker
Starting Member
7 Posts |
Posted - 2007-09-10 : 05:21:37
|
| Hi,I want to use something like select count(*) from table name = 0; to check whether a table is empty,is this possible?Thanks for any info.Al. |
|
|
PeterNeo
Constraint Violating Yak Guru
357 Posts |
Posted - 2007-09-10 : 05:56:57
|
| Try this, if all statistics are updated then only it wll give exact no of rowsSelect so.[Name] as 'TblName', si.rows as 'Count'From sys.sysobjects soInner join sys.sysindexes si On so.id = si.idWhere so.xtype = 'u' and si.indid < 2Order By si.rowselse u have to use dynamic sql with loop |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-09-10 : 06:11:37
|
[code]IF (SELECT COUNT(*) FROM Table1) = 0 THEN .... ELSE ....[/code][code]IF EXISTS (SELECT * FROM Table1) THEN .... ELSE ....[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
albaker
Starting Member
7 Posts |
Posted - 2007-09-10 : 06:35:40
|
| Thank you. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-09-11 : 06:05:06
|
| Note that IF EXISTS method is faster than other methods to check existance of the dataMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|