11/25/2024 2:21:26 PM
|
|
slxdeveloper.com Community Forums |
|
|
|
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
Forum to discuss SQL Server or Oracle database administration related to SalesLogix databases. View the code of conduct for posting guidelines.
|
|
|
|
Stripping the DB of all records
Posted: 19 Dec 07 9:40 AM
|
I was presented with quite a challenge today. I was given a copy of our Production DB and instructed to remove ALL Accounts and Contacts, but one - for presentation purposes. I can definitely think of a long and painful way to do this. My question is - is there an extra card in somebody's sleeve that could ease my pain?
Thanks in advance, as always. |
|
|
|
Re: Stripping the DB of all records
Posted: 19 Dec 07 10:26 AM
|
Not sure on this one but thinking off the top of my head. You don't have to worry about sync since this is just for presentation purposes. Why not just run a few SQL statements like this:
DELETE FROM account WHERE accountid <> 'YOURACCOUNTID' DELETE FROM contact WHERE accountid <> 'YOURACCOUNTID' DELETE FROM address WHERE entityid NOT IN ('ACCOUNTID', 'CONTACTID1', 'CONTACTID2',...) AND left(entityid,1) NOT IN ('U','N') DELETE FROM opportunity WHERE accountid <> 'YOURACCOUNTID' DELETE FROM ticket WHERE accountid <> 'YOURACCOUNTID' DELETE FROM history WHERE accountid <> 'YOURACCOUNTID' (The assumption here is you only have the one account so it will keep the contact history).
This should remove the bulk of your records. I have not tested this so do it in a test. Also after you do this you can use the logic to remove some of the other tables (I left out Activity table, etc.). |
|
|
|
Re: Stripping the DB of all records
Posted: 19 Dec 07 10:34 AM
|
Here is a sample of a script that I use. My custom table start with c_
print 'delete from account' delete from account where createdate >= '2005-09-1' go
print 'delete from accountsummary' delete from accountsummary where not exists (select * from account where accountid = accountsummary.accountid) go
print 'delete from c_account' delete from c_account where not exists (select * from account where accountid = c_account.accountid) go
print 'delete from c_profile' delete from c_profile where not exists (select * from account where accountid = c_profile.accountid) go
print 'delete from contact' delete from contact where not exists (select * from account where accountid = contact.accountid) go
print 'delete from c_contact' delete from c_contact where not exists (select * from contact where contactid = c_contact.contactid) go
print 'delete from c_contact_profile' delete from c_contact_profile where not exists (select * from contact where contactid = c_contact_profile.contactid) go
print 'delete account addresses' delete from address where entityid like 'a%' and entityid not in ('ADMIN') and not exists (select * from account where accountid = address.entityid) go
print 'delete contact addresses' delete from address where entityid like 'c%' and not exists (select * from contact where contactid = address.entityid) go
print 'detete from c_transactions' delete from c_transactions where not exists (select * from account where accountid = c_transactions.accountid) go
print 'detete from history' delete from history where (Accountid is not null and not exists (select * from account where accountid = history.accountid)) or (Contactid is not null and not exists (select * from contact where contactid = history.contactid)) go
print 'detete from activity' delete from activity where (Accountid is not null and not exists (select * from account where accountid = activity.accountid)) or (Contactid is not null and not exists (select * from contact where contactid = activity.contactid)) go
|
|
|
|
Re: Stripping the DB of all records
Posted: 20 Dec 07 3:40 AM
|
Yes, the long and painful way is to create a group that doesn't contain your record and then purge the rows via SLX. Other ways are to delete from all tables and hope you don't trip over slx tables (like user, address, systeminfo etc). Enclosed is a script from ToddHardin that does the trick very well - you will need to modify to keep your one record.
-- Author: Todd Hardin, Customer Systems Inc. -- -- Revisions: -- 2004/11/23 First release for SLX v6.2 -- -- Purpose: -- Clean-out a previously configured SLX database for re-import of all data -- Non-system data tables are truncated. -- Special handling is implemented for the hybrid system-user table: ADDRESS -- -- Note that the definition of "clean-out" may vary for each situation and this -- script should be adjusted accordingly. -- -- Assumptions: -- User is logged into MS-SQL using SYSDBA account -- -- CAUTION: -- The user is advised to first run this script in TruncateMode = OFF in order to review -- the list of tables that will be truncated. -- -- The user is advised to make a full backup of the database before executing this script. -- -- NOTE: Assumes user is logged in as SYSDBA user -- --
print 'Begin CleanDB Script'
declare @TruncateMode varchar(16) select @TruncateMode = 'OFF' -- {ON | OFF} Print 'TruncateMode is: ' + @TruncateMode Print ' '
if @TruncateMode = 'ON' Begin -- Special handling for the Address table -- SLX stores two address records each for: -- A. Users -- B. Offices -- You must have these address records in the address table -- or SLX will not function correctly due to inner joins -- performed by SLX. -- This step extracts the User and Office records from ADDRESS table into -- a work table used at end of script. --
-- Drop Temp address table if exists print 'Dropping temporary address work table if it exists' if exists (select * from dbo.sysobjects where id = object_id(N'[zTempAddress]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [zTempAddress]
-- Create temp address table, populate with SYSTEM and USER addresses records only print 'Creating Temporary address table - populate with User and Office address records' select address.* into zTempAddress from address where addressid in ( select userinfo.addressid from userinfo UNION select userinfo.homeaddressid from userinfo UNION select branchoptions.addressid from branchoptions UNION select branchoptions.shippingid from branchoptions ) End -- @TruncateMode = 'ON'
-- declare tablelist cursor for select table_name from information_schema.tables -- exclude tables that should not be truncated -- IMPORTANT NOTE: your specific needs may vary - please edit (uncomment) accordingly -- Various types of tables to NOT truncate: -- A. Work tables used by this script -- B. SLX SYSTEM configuration tables -- C. SLX USER configuration tables -- D. PRODUCT definition tables -- E. Defect, Ticket, Campaign, etc. - feature configuation tables -- F. Custom tables you have created should not be truncated
-- To allow a table to be cleared (Truncated), -- use comment to remove the table name from the truncation exclusion list.
declare tablelist cursor for select table_name from information_schema.tables where table_schema = 'sysdba' and table_type = 'base table' and table_name not in ( 'ZTEMPADDRESS', -- Do NOT truncate - special work table for this script -- 'ACCOUNTINGSYSINFO', -- optional: possibly customized for account application integration 'ADMINROLES', 'AGENTS', 'ALERT', 'ALERTNOTIFY', -- 'AREACATEGORYISSUE', -- optional: do not truncate, probably customized 'BRANCHOPTIONS', 'CALCULATEDFIELDDATA', -- 'CAMPAIGN', -- optional: do not truncate, probably customized -- 'CAMPAIGNTASK', -- optional: do not truncate, probably customized 'COLLECTIONDEFS', 'COLLECTIONFILES', 'COLLECTIONPATH', 'COLLECTIONSTATS', 'COLLECTIONUPDATES', 'CONCURRENTUSER', 'CONTROLCLASSES', 'CUSTOMSETTINGS', -- If Defect Feature has already been configured, you may wish to retain -- 'DEFECT', -- optional: possible custom values to retain -- 'DEFECTACTIVITYITEM', -- optional: possible custom values to retain -- 'DEFECTACTIVITYRATE', -- optional: possible custom values to retain -- 'DEFECTHISTORY', -- optional: possible custom values to retain -- 'DEFECTLINKACTSTATUS', -- optional: possible custom values to retain -- 'DEFECTPROBLEM', -- optional: possible custom values to retain -- 'DEFECTPRODUCT', -- optional: possible custom values to retain -- 'DEFECTSOLUTION', -- optional: possible custom values to retain -- 'EVENT', -- Administrator defined Events (holidays, etc.) -- 'EXCHANGERATE', -- Currency Exchange rates -- 'INDEXDEFINITION', -- SpeedSearch index definitions -- 'INDEXSCHEDULE', -- SpeedSearch schedule per index defined 'JOINDATA', 'LANGUAGETRANSLATION', -- 'LEADSOURCE', -- optional: possible custom leadsources defined -- 'LIBRARYDIRS', -- optional: possible custom Sales Library folders and docs -- 'LIBRARYDOCS', -- optional: possible custom Sales Library folders and docs 'LICENSES', -- 'LITERATURE', -- optional: possible custom literature defined for litrequest feature 'LOOKUP', 'META_CLASS', 'META_CLASSFUNCTION', 'META_FUNCTION', 'NOTIFICATIONCONFIG', -- 'PACKAGEPRODUCT', -- optional: possible custom products with prod package defintions -- 'PACKAGES', -- optional: possible custom package (product packaging) definitions 'PICKLIST', 'PLUGIN', 'PLUGINATTACHMENT', 'PLUGINEXTS', -- 'POSTALCODE', -- optional: not used by SLX, but possibly used by custom code -- 'PROCEDURECONTRIBUTOR', -- optional: possible custom support proceedures defined -- 'PROCEDURES', -- optional: possible custom support proceedures defined -- 'PRODUCT', -- optional: possible custom products defined -- 'PRODUCTPROGRAM', -- optional: possible custom product programs defined 'PROJECT', 'PROJECTPLUGIN', -- 'QUOTA', -- optional: possible custom sales quotas per user defined 'REALIGNPROFILE', 'REMOTETASKS', -- 'RESOURCELIST', -- optional: possible custom calendar resources defined (rooms, equipment, etc.) 'RESYNCTABLEDEFS', 'SEC_FUNCTIONOWNER', 'SECCODE', 'SECCODEJOINS', 'SECFUNCTIONS', 'SECPROFILE', 'SECRIGHTS', 'SECRIGHTSCACHE', 'SECTABLEDEFS', 'SITE', 'SITEKEYS', 'SITEOPTIONS', -- 'SKILLCATEGORY', -- optional: possible custom skillcategories defined per support user 'SLXBUNDLE', 'SLXTRIGGERS', 'SLXWEBACTION', 'SLXWEBALIAS', 'SLXWEBDATA', 'SLXWEBOVERRIDE', 'SLXWEBQUERY', 'SLXWEBSERVER', 'SLXWEBTEMPLATE', 'SLXWEBUSERINFO', 'SUBSCRIPTIONRULES', 'SYNCFILETRACKING', 'SYNCJOBHISTORY', 'SYNCSEQUENCING', 'SYNCSERVER', 'SYNCSERVICEFILE', 'SYNCTRANSFER', 'SYSTEMINFO', -- 'TICKETACTIVITYRATE', -- optional: possible custom configuration values -- 'TICKETAREAOWNER', -- optional: possible custom configuration values (per user) -- 'TICKETPROBLEMSOLUTIONTYPE', -- optional: possible custom configuration values -- 'TICKETPROBLEMTYPE', -- optional: possible custom configuration values -- 'TICKETSOLUTIONTYPE', -- optional: possible custom configuration values -- 'URGENCY', -- optional: possible custom support problem urgency levels 'USERCALENDAR', 'USERINFO', 'USEROPTIONDEF', 'USEROPTIONS', 'USERSECFUNCTIONS', 'USERPRODUCT', 'USERPROFILE', 'USERSALES', 'USERSECURITY', 'USERSUBSCRIPTION', 'USERVIEW', 'WORKAREA', ) order by table_name
declare @TableName sysname declare @TableCounter int select @TableCounter = 0
open tablelist fetch next from tablelist into @TableName while @@fetch_status = 0 begin select @TableCounter = @TableCounter + 1 print 'Processing Table: ' + @TableName exec('declare @RowCount bigint select @RowCount = count(*) from ' + '[' + @TableName + ']' + ' Print ''Record Count for table: '' + ''' + @TableName + ''' + '' is '' + CAST(@RowCount as varchar(10)) ')
if @TruncateMode = 'OFF' Begin print 'TruncateMode is OFF, skipping actual truncation task' End if @TruncateMode = 'ON' Begin print 'Truncate Mode is ON, executing truncate statement' exec('Truncate Table ' + @TableName) exec('declare @RowCount bigint select @RowCount = count(*) from ' + '[' + @TableName + ']' + ' Print ''Record Count for table: '' + ''' + @TableName + ''' + '' is '' + CAST(@RowCount as varchar(10)) ') End print ' ' fetch next from tablelist into @TableName end close tablelist deallocate tablelist
-- Re-populate the now empty Address table with USER and SYSTEM address records if @TruncateMode = 'ON' Begin print 'Recovering Office and User address records' -- must use EXEC because table does not actually exist until script is run -- query analyzer validation happens before script is run, thus table is missing. insert into Address select * from zTempAddress
-- Drop Temp address table if exists (select * from dbo.sysobjects where id = object_id(N'[zTempAddress]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [zTempAddress] End
print 'CleanDB Script Complete - please review output for errors' |
|
|
|
Re: Stripping the DB of all records
Posted: 20 Dec 07 10:35 AM
|
As an additional item that you might find helpful, I wrote a script for myself that gives me all the tables in my SalesLogix database, grabs the number of records in each table, and outputs it to Excel. It only works on SQL Server 2005, though, so hope that doesn't mess you up.
Sub btnGrabTableInfoClick(Sender) Dim theCon, strSQL, theRS, theRS2, i, x, strPreviousNewStatus, iNextRow Dim xlApp, xlWb, xlWs, strAppVersion Set xlApp = CreateObject("Excel.Application") Set xlWb = xlApp.Workbooks.Add Set xlWs = xlWb.Worksheets("Sheet1") strAppVersion = Mid(xlApp.Version, 1, InStr(1, xlApp.Version, ".") - 1) xlApp.Visible = True xlApp.UserControl = True iNextRow = 5
If CDbl(strAppVersion) > 8 Then 'Insert Title to Worksheet xlWs.Range("A1:Z4").Font.Bold = True xlWs.Cells(1, 1).Value = "List of Table Names in User and the Number of Records" xlWs.Cells(2, 1).Value = "Printed: " & FormatDateTime(Now, 2)
' Set the column names using the Caption text from the grid xlWs.Cells(4, 1).Value = "Table Name" xlWs.Cells(4, 2).Value = "Number of Records"
Set theCon = Application.GetNewConnection strSQL = "SELECT DISTINCT Table_Name FROM Information_Schema.Columns WHERE Table_Schema = 'sysdba'" Set theRS = theCon.Execute(strSQL) ProgressBar.Max = theRS.RecordCount
For i = 1 To theRS.RecordCount If Not Right(theRS("Table_Name"), 1) = "_" And theRS("Table_Name") = UCase(theRS("Table_Name")) Then xlWs.Cells(iNextRow, 3).Value = theRS("Table_Name") strSQL = "SELECT Count(*) AS NumberOfRecords FROM " & theRS("Table_Name") Set theRS2 = theCon.Execute(strSQL) If theRS2.RecordCount > 0 Then If theRS2("NumberOfRecords") > 0 Then xlWs.Cells(iNextRow, 1).Value = theRS("Table_Name") xlWs.Cells(iNextRow, 2).Value = FormatNumber(theRS2("NumberOfRecords"), 0) xlWs.Cells(iNextRow, 3).Value = "" iNextRow = iNextRow + 1 End If xlWs.Cells(iNextRow, 3).Value = "" End If theRS2.Close Set theRS2 = Nothing xlWs.Cells(iNextRow, 3).Value = "" End If theRS.MoveNext lblRecordCount.Caption = "Record " & (i) & " of " & theRS.RecordCount ProgressBar.StepIt Application.BasicFunctions.ProcessWindowMessages Next
xlWs.Range("A4:D300").Columns.AutoFit Else MsgBox "MS Excel 2000 or newer needs to be installed to export this list.", vbOKOnly, "Export to Excel" End If
Set xlWs = Nothing Set xlWb = Nothing Set xlApp = Nothing
theRS.Close Set theRS = Nothing theCon.Close Set theCon = Nothing
Msgbox "Finished!", 0, "SalesLogix" End Sub
As you can imagine, it takes several minutes to run, but I love the information I get out of it. The form has a label called lblRecordCount and a progress bar so I can monitor progress as it is doing its thing. |
|
|
|
Re: Stripping the DB of all records
Posted: 03 Jan 08 3:13 PM
|
Mike
Our sys wiz was not able to provide me the sysdba pw for the copy of the SLX DB, however he assigned a sysdba role to my login. When I run the script with Truncate Mode = ON, I get an error on line 55 - "Invalid object name 'address'."
Is that because I am not logged in as sysdba? I see the address table. |
|
|
|
Re: Stripping the DB of all records
Posted: 03 Jan 08 3:19 PM
|
Assuming it's this line:
select address.* into zTempAddress from address
Yes, I would say it was (script assumes and does say - needs to be running as sysdba) - try running it as sysdba first (have your syswiz log you in !). If that works - then you'll probably need to adjust the script to preface all non-identified tables with select x from sysdba.tablename
Cheers Mike
|
|
|
|
Re: Stripping the DB of all records
Posted: 03 Jan 08 4:41 PM
|
Or (in SS2005) add the following line at the beginning of the script (assuming the user has IMPERSONATE privileges):
execute as login = 'sysdba'
PP |
|
|
|
Re: Stripping the DB of all records
Posted: 03 Jan 08 4:52 PM
|
Originally posted by Jeff Weight
As an additional item ... --edit strSQL = "SELECT DISTINCT Table_Name FROM Information_Schema.Columns WHERE Table_Schema = 'sysdba'" --edit
|
|
Hi Jeff - just looked at this & have a suggested change:
strSQL = "SELECT Table_Name FROM Information_Schema.Tables WHERE Table_Schema = 'sysdba'"
Just a bit tidier than doing the DISTINCT ...
Cheers Phil
|
|
|
| |
|
Re: Stripping the DB of all records
Posted: 04 Jan 08 7:51 AM
|
Mike
Executed the script under sysdba login, still got the error, but strangely all tables were stripped as they were supposed to. Go figure |
|
|
|
Re: Stripping the DB of all records
Posted: 10 Feb 08 11:39 AM
|
Nice script. I got it to run on SQL2000 with a small change.
Change...
strSQL = "SELECT DISTINCT Table_Name FROM Information_Schema.Columns WHERE Table_Schema = 'sysdba'"
to...
strSQL = "SELECT DISTINCT Name as Table_Name FROM dbo.sysobjects WHERE xtype = 'U' and uid = (select uid from dbo.sysusers where name = 'sysdba')"
|
|
|
|
Re: Stripping the DB of all records
Posted: 11 Feb 08 9:11 AM
|
Mike, That's a very nice SQL script and I'll keep it in mind for the future. I was just wondering, why not just install the blank DB from the installation DVD and then add the single record set (Account, etc.) that is requested for the demo? Bob
|
|
|
|
Re: Stripping the DB of all records
Posted: 11 Feb 08 4:38 PM
|
Robert
An example of where you would use such a script is where you are doing repeated data conversions into a client's customised database. 'Repeated' because the damn thing just doesn't quite work how you want the first few times Clearly the blank db is no good here, as it does not have all the required bundles etc. Doing a purge via SLX is slow if there are a lot of records. This way is the fastest - it does not touch customisations/meta data, just the 'proper' data.
Cheers Phil |
|
|
|
Re: Stripping the DB of all records
Posted: 12 Feb 08 8:30 AM
|
Phil, Very good point. Not only would I have to re-install the bundles, but sometimes selective plugin releases to specific teams can also be a burden.
|
|
|
|
You can
subscribe to receive a daily forum digest in your
user profile. View the site code
of conduct for posting guidelines.
Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
|
|
|
|
|
|
|
|