Logic for comparing and deleting...

  • 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

  • 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,

    127.0.0.1 [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

  • Anyone have any ideas or thoughts on this?

  • Apparently no one responded here so OP started a new thread here. Please post any responses in the new thread.

  • Sorry - I was desparate for some help

    :w00t:

  • 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.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply