Hi Joe!
I found this link on the internet because that's exactly what I'm working on this morning.
select t.name TableName, i.rows Records
from sysobjects t, sysindexes i
where t.xtype = 'U' and i.id = t.id and i.indid in (0,1) and i.rows > 0
order by TableName;
Another approach:
select t.name TableName, i.rows Records
from sysobjects t, sysindexes i
where t.xtype = 'U' and i.id = t.id and i.indid in (0,1) and i.rows > 0
order by TableName;
select schema_name(tab.schema_id) + '.' + tab.name as [table],
sum(part.rows) as [rows]
from sys.tables tab
inner join sys.partitions part
on tab.object_id = part.object_id
where part.index_id IN (1, 0) -- 0 - table without PK, 1 table with PK
group by schema_name(tab.schema_id) + '.' + tab.name
order by sum(part.rows) desc
Once I've got it cleared out, I will back up and restore into TEMPLATEDB so it's available for re-use when this comes up again.
Stay safe!
------------------------------
Gail Jones-Nemeth
Financial Systems Analyst
Creative Associates Int'l
Washington DC
------------------------------
Original Message:
Sent: Jan 23, 2021 10:40 PM
From: Joe Miller
Subject: Copy DB to New Company, Clear Non-Setup Tables
Before I go building one out on my own, does anybody out there have a SQL script that they run to "clear" all the transaction tables in a database in order to use it for a new company? We have several companies and are starting a new one that will be similar in setup to the others, we want to basically take one of the existing companies and wipe it preserving the setup tables so we can start fresh. I've done it before with smaller companies that don't use as many tables, but the one I'm about to clone is a much larger database and has more usage so figured I'd ask before I went to town. Thanks all!
Joe
------------------------------
Joe Miller
Director of Systems Architecture
Harrison, Walker & Harper
Paris TX
------------------------------