ptheriault
IS-IT--Management
You guys may know this but I didn't. I stumbled accross this last while searching for Joe Celko's latest book.
A user executes the following two queries in SQL Server Query Analyzer. Query 1 returns no rows; Query 2 returns one row. Why?
- Paul
- If at first you don't succeed, find out if the loser gets anything.
A user executes the following two queries in SQL Server Query Analyzer. Query 1 returns no rows; Query 2 returns one row. Why?
Code:
--QUERY 1
SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'ExampleTable'
AND COLUMN_NAME = 'Description'
--QUERY 2
SELECT * FROM sysobjects, syscolumns
WHERE sysobjects.id = syscolumns.id
AND sysobjects.name = 'ExampleTable'
AND syscolumns.name = 'Description'
Note: This is of importance if you are using the clause in an insert script:
IF NOT EXISTS (SELECT * FROM sysobjects, syscolumns WHERE sysobjects.id = syscolumns.id
AND sysobjects.name = 'ExampleTable'
AND syscolumns.name = 'Description')
alter table dbo.ExampleTable add Description varchar(50)
GO
- Paul
- If at first you don't succeed, find out if the loser gets anything.