Re: MS SQL copy new and modified rows from TABLE1 to TABLE2



On Aug 16, 2:14 pm, Yas <yas...@xxxxxxxxx> wrote:
On 16 Aug, 13:46, Erland Sommarskog <esq...@xxxxxxxxxxxxx> wrote:

The first question is why do you want to do this in the first place? It
seems funny that you would want to have two identical tables in the same
database? Or ar the tables in different databases on different servers?

Hi, sorry perhaps I should have been a bit more clear. Well, Table2 is
essentially a Master table that will have a record of all users that
were ever added to Table1. So even if at a later date userA and userB
were removed from Table1, a record of UserA and UserB will always be
there in Table2.

So yes right now Table1 and 2 are identical and that seems
pointless...however soon Table2 will be different in that it will have
a record of rows that are no longer present in Table1. I'm keeping
track of them via another method which checks if a row has been
removed from Table1 if so it adds the date of removal to a column of
that row in Table2. This is why I dont want to update Table2 if a row
is removed in Table1...only if a new row is added or an existing one
modified.

I hope that explains what I'm trying to do :-) can I still use
Triggers to do this?

If the tables are on the same server, a trigger would be the best way
to do it.

Yes, they are on the same server and in the same Database.

Couldn't you just use one table and add column use as a DELETED flag
to logically delete a user so the physical row is still there?

.



Relevant Pages

  • Re: MS SQL copy new and modified rows from TABLE1 to TABLE2
    ... Or ar the tables in different databases on different servers? ... were ever added to Table1. ... there in Table2. ... they are on the same server and in the same Database. ...
    (comp.databases.ms-sqlserver)
  • Re: Move record from one table to another
    ... Building a database isn't like building ... Set a "pushFlag" column in the record in table1 to a specific ... Sets the "status" field in the new record in table2 to a specific ... If a duplicate is not found, ...
    (comp.databases.ms-access)
  • Re: Noob question on Access table merging
    ... database, some of the items I already have in my database. ... Now create a query with Table1 and Table2. ... Dbl-Click on it and select the option to select All records from Table1 and only those that match in Table2. ...
    (comp.databases.ms-access)
  • Re: counting in a query
    ... Say you've got two instances of 12345 in table1 ... and only one in table2. ... >>> How do I get it to give me a count of the zip5 field in each database ... >>> Joe Robison ...
    (microsoft.public.fox.programmer.exchange)
  • Re: real world singleton class example?
    ... I've used them for database classes before. ... What is the use of a singleton is when running PHP? ... table1 and table2 tables within the database. ...
    (comp.lang.php)