Wednesday, February 15, 2012

Empty a Database SQL 2000

Hello,
Is there a way to export a database and delete the contents of it as
it creates the backup - leaving the database intact but devoid of
data?
Thanks,
Tmuld
Hi,
You could create SP which uses BACKUP and TRUNCATE TABLE statement, I
guess. Is it something you want, or is there another constraint?
Tmuldoon wrote:
> Hello,
> Is there a way to export a database and delete the contents of it as
> it creates the backup - leaving the database intact but devoid of
> data?
> Thanks,
> Tmuld
>
|||See Dan's post some times ago
DECLARE @.TruncateStatement nvarchar(4000)
DECLARE TruncateStatements CURSOR LOCAL FAST_FORWARD
FOR
SELECT
N'TRUNCATE TABLE ' +
QUOTENAME(TABLE_SCHEMA) +
N'.' +
QUOTENAME(TABLE_NAME)
FROM
INFORMATION_SCHEMA.TABLES
WHERE
TABLE_TYPE = 'BASE TABLE' AND
OBJECTPROPERTY(OBJECT_ID(QUOTENAME(TABLE_SCHEMA) +
N'.' +
QUOTENAME(TABLE_NAME)), 'IsMSShipped') = 0
OPEN TruncateStatements
WHILE 1 = 1
BEGIN
FETCH NEXT FROM TruncateStatements INTO @.TruncateStatement
IF @.@.FETCH_STATUS <> 0 BREAK
RAISERROR (@.TruncateStatement, 0, 1) WITH NOWAIT
EXEC(@.TruncateStatement)
END
CLOSE TruncateStatements
DEALLOCATE TruncateStatements
"Tmuldoon" <tmuldoon@.spliced.com> wrote in message
news:1185920307.362745.28610@.d30g2000prg.googlegro ups.com...
> Hello,
> Is there a way to export a database and delete the contents of it as
> it creates the backup - leaving the database intact but devoid of
> data?
> Thanks,
> Tmuld
>

No comments:

Post a Comment