Friday, December 5, 2008

How To Delete GP Company

I got allot of questions on how to delete company from GP, script below is the answer:

CAUTION: Do not delete the company from Enterprise Manager first (step 2). If this
is done, you will need to run SQL scripts to delete database tables individually. You
will need to delete any references to the company in several DYNAMICS tables. The
example below shows a list of some of the tables that might need to be removed.
Example:
Use DYNAMICS
Select * from DYNAMICS…SY01500
The result set shows you the CMPANYID and INTERID fields for your company. Run
the following script, replacing "-1" with CMPANYID and "TWO" with INTERID with
your company’s information:
Use DYNAMICS
go
delete MC60100 where CMPANYID = -1
delete MC60200 where CMPANYID = -1
delete SY00801 where CMPANYID = -1
delete SY01500 where CMPANYID = -1
delete SY01900 where CMPANYID = -1
delete SY02000 where CMPANYID = -1
delete SY02100 where CMPANYID = -1
delete SY05200 where CMPANYID = -1
delete SY40500 where CMPANYID = -1
delete SY60100 where CMPANYID = -1
delete UPR10300 where CMPANYID = -1
delete UPR10304 where CMPANYID = -1
delete W200002 where CMPANYID = -1
delete DU000020 where companyID = -1
delete DU000030 where companyID = -1
delete DB_Upgrade where db_name = 'TWO'

Regards,
--
Mohammad R. Daoud
MCP, MCBMSP, MCTS, MCBMSS
Software Development Manager
+962 - 79 - 999 65 85
Dynamics Innovations
daoudm@dynamicsinnovations.com
http://www.dynamicsinnovations.com/

2 comments:

Mariano Gomez said...

Mohammad,

While I like this solution because it's simplicity, it's not quite as portable across versions. You may want to try something a bit more generic, as follows:

use DYNAMICS
go

-- go after CMPANYID column
declare @table varchar(100)
declare c_company cursor for
select distinct rtrim(objs.name)
from syscolumns cols
inner join sysobjects objs on (cols.id = objs.id)
inner join sysindexes indx on (cols.id = indx.id)
where (cols.name = 'CMPANYID') and (objs.xtype = 'U') and (indx.rowcnt <> 0)

open c_company
fetch next from c_company into @table

while @@FETCH_STATUS = 0
begin
exec('DELETE FROM ' + rtrim(@table) + ' WHERE CMPANYID = -1')
fetch next from c_company into @table
end

close c_company
deallocate c_company

-- go after INTERID column
declare c_company cursor for
select distinct rtrim(objs.name)
from syscolumns cols
inner join sysobjects objs on (cols.id = objs.id)
inner join sysindexes indx on (cols.id = indx.id)
where (cols.name = 'INTERID') and (objs.xtype = 'U') and (indx.rowcnt <> 0)

open c_company
fetch next from c_company into @table

while @@FETCH_STATUS = 0
begin
exec('DELETE FROM ' + rtrim(@table) + ' WHERE INTERID = ''TWO''')
fetch next from c_company into @table
end

close c_company
deallocate c_company

-- go after DB_NAME column
declare c_company cursor for
select distinct rtrim(objs.name)
from syscolumns cols
inner join sysobjects objs on (cols.id = objs.id)
inner join sysindexes indx on (cols.id = indx.id)
where (cols.name = 'DB_NAME') and (objs.xtype = 'U') and (indx.rowcnt <> 0)

open c_company
fetch next from c_company into @table

while @@FETCH_STATUS = 0
begin
exec('DELETE FROM ' + rtrim(@table) + ' WHERE DB_NAME = ''TWO''')
fetch next from c_company into @table
end

close c_company
deallocate c_company

Best regards,

MG.-
Mariano Gomez, MVP
www.maximumglobalbusiness.com

Mohammad Daoud said...

Very thanks for the correction :)

Related Posts:

Related Posts with Thumbnails