Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Logic for comparing and deleting... Expand / Collapse
Author
Message
Posted Tuesday, August 14, 2012 12:16 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Friday, October 17, 2014 5:02 PM
Points: 485, Visits: 1,368
I know this probably is a lot more easy to construct than I can construct (in my non-developer mind), but basically what I need to put together is the following:

- T-SQL code to compare the records in 1 table of 1 database in the default instance against another identical table in another database in the default instance.

I have about 140 million rows in the tables, and unfortunately the main table of the main database in this scenario has new rows added daily (not many but enough that I need some sort of logic to see what those are).

The logic needs to do this...

- Compare the rows of the 2 tables.
- Delete the rows in the main database table that has those rows in the other identical database table.

I figure if I can get these 2 steps put together, I will wind up with new rows in the main table that I can then run a job against later in the evening to copy them over to the other identical table in the other database. That way I can repeat this cycle, and have a way to maintain a consistent method of archiving these rows out and freeing up space for the main database by deleting the dups.

Reason I am doing this is that the main database is running out of disk space. They will not even consider SSIS for this (don't ask me why - it's a whole other can of worms), and so to free up space for the disk that the database is residing on, I need to arch these rows to this other database (which obviously resides on a different drive). It's going to free up about 45gb of space for me (which isn't much for the size of this database, but enough for me to have it limp along until a migration I am working on in tandem to this is finally approved).

Any help from any of your Gurus would be greatly appreciated!

SQL_ME_RICH
Post #1344945
Posted Tuesday, August 14, 2012 12:20 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Friday, October 17, 2014 5:02 PM
Points: 485, Visits: 1,368
P.S. Here is the table in the target database (where the records will eventually be copied to...The only difference between this table, and the table in the main database is that the ConnectionID column is a PKey with a Clustered Index where this table is just a heap).

USE [yQueue_Archive]
GO
/****** Object: Table [dbo].[yConnections] Script Date: 08/14/2012 11:18:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[yConnections](
[ConnectionID] [varchar](30) NOT NULL,
[GUID] [uniqueidentifier] NULL,
[IP] [varchar](50) NULL,
[Interface] [varchar](20) NULL,
[Carrier] [varchar](20) NULL,
[Connects] [int] NULL,
[Disconnects] [int] NULL,
[KeepAlives] [int] NULL,
[TrxIn] [int] NULL,
[TrxOut] [int] NULL,
[TrxOutSMS] [int] NULL,
[TrxErrors] [int] NULL,
[TrxExceptions] [int] NULL,
[BytesIn] [bigint] NULL,
[BytesOut] [bigint] NULL,
[StampStart] [smalldatetime] NULL,
[StampLast] [smalldatetime] NULL,
[Serial] [varchar](20) NULL,
[LastStatus] [varchar](20) NULL,
[MaxQueueTime] [smallint] NULL,
[AvgQueueTime] [smallint] NULL,
[HealthIndex] [smallint] NULL
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF

Post #1344950
Posted Tuesday, August 14, 2012 6:34 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Friday, October 17, 2014 5:02 PM
Points: 485, Visits: 1,368
Anyone have any ideas or thoughts on this?
Post #1345098
Posted Wednesday, August 15, 2012 3:17 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 11:57 AM
Points: 20,734, Visits: 32,509
Apparently no one responded here so OP started a new thread here. Please post any responses in the new thread.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1345568
Posted Wednesday, August 15, 2012 3:22 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Friday, October 17, 2014 5:02 PM
Points: 485, Visits: 1,368
Sorry - I was desparate for some help

Post #1345574
Posted Wednesday, August 15, 2012 3:31 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 11:57 AM
Points: 20,734, Visits: 32,509
SQL_ME_RICH (8/15/2012)
Sorry - I was desparate for some help



Bumping the curent thread would have been an acceptable alternative to double posting. I'd seen this thread yesterday as I was leaving for an appointment, and then just forgot about afterward.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1345581
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse