Accessing multiple .sdf databases in a single sql statement

  • Hello,

    I would like to execute this statement below. However, Table1 and Table2 reside in two separate databases. I am not sure how I would reference the two databases? I know how to do it with one.

    DELETE FROM Table1

    WHERE EXISTS

    (SELECT Table2.AID

    FROM Table2

    WHERE (Table2.AID = Table1.AID))

    This is what I do when accessing one database:

    SqlCeConnection conn = null;

    conn = new SqlCeConnection(TSDataAccess.CONN_STRING);

    conn.Open();

    SqlCeCommand cmd = conn.CreateCommand();

    cmd.Connection = conn;

    cmd.CommandText = "

    DELETE FROM Table1

    WHERE EXISTS

    (SELECT Table2.AID

    FROM Table2

    WHERE (Table2.AID = Table1.AID))";

    cmd.ExecuteNonQuery();

    conn.Close();

    Is it even possible to accomplish this with multiple databases? If not, what other alternatives do I have?

    Any help or guiduance would be greatly appreciated.

    Thanks!

    Anita

  • You need to add a linked server in your current sql server if the 2nd database lies on sql database server other than the server on which your 1st database resides and refer to the table with

    [linkedservername].databasename.tablename

    if the database is on the same sql server instance then simply specity databasename.tablename

Viewing 2 posts - 1 through 1 (of 1 total)

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