Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does SQL Server 2000 treat SELECT test.* and SELECT t.est.* the same?

Tags:

I butter-fingered a query in SQL Server 2000 and added a period in the middle of the table name:

SELECT t.est.* FROM test 

Instead of:

SELECT test.* FROM test 

And the query still executed perfectly. Even SELECT t.e.st.* FROM test executes without issue.

I've tried the same query in SQL Server 2008 where the query fails (error: the column prefix does not match with a table name or alias used in the query). For reasons of pure curiosity I have been trying to figure out how SQL Server 2000 handles the table names in a way that would allow the butter-fingered query to run, but I haven't had much luck so far.

Any sql gurus know why SQL Server 2000 ran the query without issue?

Update: The query appears to work regardless of the interface used (e.g. Enterprise Manager, SSMS, OSQL) and as Jhonny pointed out below it bizarrely even works when you try:

SELECT TOP 1000 dbota.ble.* FROM dbo.table 
like image 291
Chris Van Opstal Avatar asked Jun 04 '10 14:06

Chris Van Opstal


2 Answers

Maybe table names are constructed from a naive concatenation of prefix and base name.

't' + 'est' == 'test' 

And maybe in the later versions of SQL Server, the distinction was made more semantic/more rigorously.

{ owner = t, table = est } != { table = test } 
like image 195
Mark Canlas Avatar answered Dec 07 '22 20:12

Mark Canlas


SQL Server 2005 and up has a "proper" implementation of schemas. SQL 2000 and earlier did not. The details escape me (its been years since I used SQL 2000), all I recall clearly is that you'd be nuts to create anything that wasn't owned by "dbo". It all ties into users and object ownership, but the 2000 and earlier model was pretty confusticated. Hopefully someone will read up on BOL, do some experimentation, and post their results here.

like image 32
Philip Kelley Avatar answered Dec 07 '22 20:12

Philip Kelley