Wednesday, March 21, 2012

Deleting data ..

Hi,
Sorry for daft question -
How to delete data in the whole database please? Deleting data table by
table is not an option.
Many thanks,
Harish Mohanbabu
Microsoft Dynamics Ax [MVP]
http://www.harishm.com/
Hi Harish,
one of possible way to achieve your goal could be:
- script any object (tables, views, DML triggers, etc) using the IF EXIST...
DROP...CREATE)
- verify and execute such script
There's a lot of issues to be resolved:
Do you have foreign keys, indexes, constraints? many of them could generate
errors if the script is executed in the wrong order...(you cannot delete
parent tables rows before deleting all the children...)
Why do you need to delete completely the data from a database?
May be in your requirements we can find suggestions for the best way to do it
Gilberto Zampatti
"Harish Mohanbabu" wrote:

> Hi,
> Sorry for daft question -
> How to delete data in the whole database please? Deleting data table by
> table is not an option.
> Many thanks,
> Harish Mohanbabu
> --
> Microsoft Dynamics Ax [MVP]
> http://www.harishm.com/
|||"Harish Mohanbabu" <Axapta@.online.nospam> wrote in message
news:EF5A8D3C-0869-43A5-BFBF-94B13EBE73C7@.microsoft.com...
> Hi,
> Sorry for daft question -
> How to delete data in the whole database please? Deleting data table by
> table is not an option.
I would script out the entire database and then drop the tables and
re-create.
Or... use the sp_msforeachtable undocumented stored proc to truncate each
table.
Oh and make sure you have a good backup first ;-)

> Many thanks,
> Harish Mohanbabu
> --
> Microsoft Dynamics Ax [MVP]
> http://www.harishm.com/
Greg Moore
SQL Server DBA Consulting Remote and Onsite available!
Email: sql (at) greenms.com http://www.greenms.com/sqlserver.html
|||I think this is the best option because also the truncate would reset any
identity fields you have in the table...
"Greg D. Moore (Strider)" wrote:

> "Harish Mohanbabu" <Axapta@.online.nospam> wrote in message
> news:EF5A8D3C-0869-43A5-BFBF-94B13EBE73C7@.microsoft.com...
> I would script out the entire database and then drop the tables and
> re-create.
> Or... use the sp_msforeachtable undocumented stored proc to truncate each
> table.
> Oh and make sure you have a good backup first ;-)
>
> --
> Greg Moore
> SQL Server DBA Consulting Remote and Onsite available!
> Email: sql (at) greenms.com http://www.greenms.com/sqlserver.html
>
>
|||Hello,
Best option will be; take the script of all the objects/permissions and
database creation and save it as a .SQL script. After this drop the database
and
use the SQL script to create the database and all its objects.
Thanks
Hari
"Harish Mohanbabu" <Axapta@.online.nospam> wrote in message
news:EF5A8D3C-0869-43A5-BFBF-94B13EBE73C7@.microsoft.com...
> Hi,
> Sorry for daft question -
> How to delete data in the whole database please? Deleting data table by
> table is not an option.
> Many thanks,
> Harish Mohanbabu
> --
> Microsoft Dynamics Ax [MVP]
> http://www.harishm.com/

No comments:

Post a Comment