Categories
SQL Server

Checking if a table exists in your SQL Server 2000 database

So you want to check, before you declare, or do anything special, whether a table exists in your database. This is important when you want to update more than one database instance and are writing a script. To do that run the following test:

IF EXISTS (select * from sysobjects where id = object_id(‘[name_of_your_table]’))

Share
Categories
SQL Server

Updating multiple table rows using a query

So you made a modification to a table and want to update many rows with values from a different table.

If you want to just insert new rows, you do:

INSERT INTO table1
SELECT val1, val2, val3
FROM table2
WHERE some condition

You need to be sure that the columns used in the insert correspond to the rows of the table you insert into.

Still, if you want to update, the syntax is slightly different:

UPDATE table1
SET col1 = t2.col3,
col2 = t2.col4
FROM table1 t1, table2 t2
WHERE t1.t1_id = t2.t1_id

Now I know…

Share
Categories
SQL Server

SQL Server 2000 Error: Cannot generate SSPI context

When trying to connect to SQL Server using Query Analyzer, you might get this perplexing error:

Unable to connect to server localhost: ODBC: Msg 0, Level 16, State 1
[Microsoft][ODBC SQL Server Driver] Cannot generate SSPI context

This appears to be a problem with the fact that SQL Server really does not like the name ‘localhost’ too much. Using 127.0.0.1 instead will do the job. Similarly, is using just the server’s name instead of the fully qualified domain name may cause a similar problem.

Share
Share