Scope of @@rowcount?

Granted, the article is for SQL Server 2000, but one would hope the scope doesn’t change between versions. According to the article How triggers affect ROWCOUNT and IDENTITY in SQL Server 2000, @@ROWCOUNT will not be affected by triggers. Specifically: It’s safe to use @@ROWCOUNT in SQL Server 2000 even when there is a trigger … Read more

Sql Server 2008 MERGE – best way to get counts

You could specify an OUTPUT clause on your MERGE statement and get an output report of what’s been done during MERGE. MERGE (targetTable) AS t USING (sourceTable) AS s ON t.ID = s.ID WHEN MATCHED THEN (some statements) WHEN NOT MATCHED THEN (some statements) OUTPUT $action, inserted.ID ‘inserted’, deleted.ID ‘deleted’ ; This will give you … Read more

How to get the number of deleted rows in PostgreSQL?

You can use RETURNING clause: DELETE FROM table WHERE condition IS TRUE RETURNING *; After that you just have to check number of rows returned. You can streamline it with CTE: WITH deleted AS (DELETE FROM table WHERE condition IS TRUE RETURNING *) SELECT count(*) FROM deleted; This should return just the number of deleted … Read more

How to fetch the row count for all tables in a SQL SERVER database [duplicate]

The following SQL will get you the row count of all tables in a database: CREATE TABLE #counts ( table_name varchar(255), row_count int ) EXEC sp_MSForEachTable @command1=’INSERT #counts (table_name, row_count) SELECT ”?”, COUNT(*) FROM ?’ SELECT table_name, row_count FROM #counts ORDER BY table_name, row_count DESC DROP TABLE #counts The output will be a list of … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)