SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Logic for comparing and deleting...


Logic for comparing and deleting...

Author
Message
SQL_ME_RICH
SQL_ME_RICH
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2460 Visits: 1596
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
SQL_ME_RICH
SQL_ME_RICH
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2460 Visits: 1596
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


SQL_ME_RICH
SQL_ME_RICH
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2460 Visits: 1596
Anyone have any ideas or thoughts on this?
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)

Group: General Forum Members
Points: 95865 Visits: 38974
Apparently no one responded here so OP started a new thread here. Please post any responses in the new thread.

Cool
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)
SQL_ME_RICH
SQL_ME_RICH
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2460 Visits: 1596
Sorry - I was desparate for some help

w00t
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)

Group: General Forum Members
Points: 95865 Visits: 38974
SQL_ME_RICH (8/15/2012)
Sorry - I was desparate for some help

w00t


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.

Cool
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)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search