- Joined
- Feb 2, 2010
- Messages
- 5,007
- Likes received
- 620
- Thanks received
- 139
- Location
- Gaul
This SQL works in SQL 2000
SELECT LogId, * FROM Logs
Order by LogId DESC
This fails in SQL 2008 with the error message
Ambiguous column name 'LogId'.
How ridiculous ? Luckily not affected too much but this could have easily meant a big migration headache.
You're selecting [LogID] twice (once in the *) so it doesn't know which one to sort by.
Assuming that does work T-SQL.
This SQL works in SQL 2000
SELECT LogId, * FROM Logs
Order by LogId DESC
This fails in SQL 2008 with the error message
Ambiguous column name 'LogId'.
How ridiculous ? Luckily not affected too much but this could have easily meant a big migration headache.
This is another reason why "select *" should NOT be used anywhere near production! Microsoft themselves advise against it.
This SQL works in SQL 2000
SELECT LogId, * FROM Logs
Order by LogId DESC
This fails in SQL 2008 with the error message
Ambiguous column name 'LogId'.
How ridiculous ? Luckily not affected too much but this could have easily meant a big migration headache.
Surely there's nothing wrong with the "select *". It's using select * and a column by name that doesn't make any sense and shouldn't suprise anyone that the behaviour might vary. Even I know that with my very limited SQL ability.
The SELECT LogId is redundant as you are doing a SELECT *.
Using * can also cause a creep in performance degradation as more columns get added to a table over time.