Error - Could not find server 'Database' in sysservers

  • Hi,

    First off, I know very little about SQL.

    I'm trying to run this code:

    UPDATE db1.dbo.Users.WebLoginID

    SET WebLoginID = "VOID"

    FROM db1.dbo.Users LEFT JOIN db2.dbo.Person

    ON db1.dbo.Users.PersonUID = db2.dbo.Person.PersonUID

    WHERE (((db2.dbo.Person.PersonUID) Is Null))

    but when I do, I get the following error:

    'Could not find server 'db1' in sysservers. Execute sp_addlinkedserver to add the server to sysservers.'

    Note that the 'server' referred to in the error message is actually a database, and the two databases I am using are on the same machine and are under the same SQL instance.

    Any suggestions on what I'm doing wrong here greatly appreciated!

    ๐Ÿ˜€

  • Hello

    The syntax for UPDATE is

    UPDATE tablename SET columnname

    You have a columnname in place of a tablename:

    db1.dbo.Users.WebLoginID

    This will probably work, though it's untested:

    UPDATE u SET WebLoginID = "VOID"

    FROM db1.dbo.Users u

    LEFT JOIN db2.dbo.Person p

    ON u.PersonUID = p.PersonUID

    WHERE p.PersonUID Is Null

    Cheers

    ChrisM

    โ€œWrite the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.โ€ - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • Are you sure that the Db1 and DB2 are databases?

    Second are you sure this is the exact code that you are running?

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • ooops well spotted Chris

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • Nearly worked! I got rid of the column, but now it gives me the error:

    Server: Msg 207, Level 16, State 3, Line 1

    Invalid column name 'VOID'.

    hmm..

    PS: Thanks for the help!

  • eflynn (11/17/2008)


    Nearly worked! I got rid of the column, but now it gives me the error:

    Server: Msg 207, Level 16, State 3, Line 1

    Invalid column name 'VOID'.

    hmm..

    PS: Thanks for the help!

    Oops! Change the double quotes for single quotes.

    โ€œWrite the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.โ€ - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • Brill! That worked..

    I had changed the quotes to single quotes before, but got scared by the red text so didn't try running it.

    Thanks a million ๐Ÿ˜‰

  • FYI, when making changes to data like this, I usually take a few precautions.

    1. Back up the table first by creating a copy with a different name, such as:

    [font="Courier New"]select * into db1.dbo.Users_20081118

    from db1.dbo.Users[/font]

    2. Run a select to see how many records will get updated and Review the data to make sure it looks like the right records:

    [font="Courier New"]select * FROM db1.dbo.Users u

    LEFT JOIN db2.dbo.Person p

    ON u.PersonUID = p.PersonUID

    WHERE p.PersonUID Is Null[/font]

    3. I would run the update in a transaction so you can undo it right then if you make a mistake:

    [font="Courier New"]begin tran

    UPDATE u SET WebLoginID = 'VOID'

    FROM db1.dbo.Users u

    LEFT JOIN db2.dbo.Person p

    ON u.PersonUID = p.PersonUID

    WHERE p.PersonUID Is Null[/font]

    If you get the correct count, then: [font="Courier New"]COMMIT[/font]

    If you think it's wrong and need to undo, then : [font="Courier New"]ROLLBACK[/font]

    4. When you're all finished, save the whole script somewhere in case you need to look back sometime.

    Record the number of rcds changed in the script

  • Good point Homebrew, however rather than risking locking users out of a live table, I'd run the update checks against the copy ๐Ÿ˜Ž

    Cheers

    ChrisM

    โ€œWrite the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.โ€ - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • Chris Morris (11/18/2008)


    Good point Homebrew, however rather than risking locking users out of a live table, I'd run the update checks against the copy ๐Ÿ˜Ž

    Cheers

    ChrisM

    You're right. I should have at least put NOLOCK in the select.

  • Thanks for the good advice guys!

  • But the Developers don't know to backup a table before doing an update. Also at my place the developer didn't make the update statement as part of the transaction and accidentally updated all the records of a table. Now I am supposed to restore it back, guess what its a customer database. This is an application role, customed made for the developers to update just one column only but still there is no scope of errors such as this...

    The_SQL_DBA
    MCTS

    "Quality is never an accident; it is always the result of high intention, sincere effort, intelligent direction and skillful execution; it represents the wise choice of many alternatives."

Viewing 12 posts - 1 through 11 (of 11 total)

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