Linda,
Hehe, I agree on that RIGHT JOIN issue. I don't think I've ever wrote one :-).
Quote:> It seems to me that for such cases where you do need a case-sensitive sort
> order, creating a whole case-sensitive instance or database is really
> overkill. Couldn't that be solved in a more elegant manner using a COLLATE
> clause on the columns where we need it?
Absolutely!
Quote:> I haven't worked with this at all
> (we're still on 7.0) so I don't know, but I'm sitting here looking at SQL
> Server 2000 BOL "Collations" topic and p. 159 of "SQL-99 Complete, Really"
> and that all appears to be supported.
I haven't actually compared syntax between BOL and SQL-99, but I assume that this was
such a late feature so that MS could implement it as per SQL-99.
Quote:> Are there any issues with this
> approach in practice that are not apparent?
A few things to consider (might be apparent).
If you correlate/compare data between collations, SQL server might then not know how
to resolve that comparison. I.e., you might have to specify COLLATE in the query
(event though you might "not care"). A couple of examples:
Cross db (collation) references. A user might think, during installation, that
selecting collation isn't a big issue, since this can be selected at db level. But
this will mean that we have a different collation in system databases then the user
databases. Cross references might then need the COLLATE keyword in the query. System
proc's, for instance.
Temp tables. A temptable created with SELECT INTO will inherit collation from result
set. But a temp table created with CREATE TABLE will inherit tempdb's collation (Kalen
showed me that we can use "database_default" as collation to get collation from
current database). Below is a script that exemplifies this (you probably don't have to
execute to understand, see comments).
--Create a database with a different collation than server default collation
CREATE DATABASE [TestDb] COLLATE Albanian_BIN
USE TestDb
--Create permanent table from which we will draw data and check collation
CREATE TABLE Permanent_(c1 CHAR(5))
SELECT collation
FROM sysobjects so INNER JOIN syscolumns sc ON so.id = sc.id
WHERE so.name like 'Permanent_'
--Create temp table with CREATE TABLE.
--Table will inherit tempdb's collation
CREATE TABLE #CT_(c1 CHAR(5))
SELECT collation
FROM tempdb..sysobjects so INNER JOIN tempdb..syscolumns sc ON so.id = sc.id
WHERE so.name like '%#CT_%'
--Create temp table with CREATE TABLE.
--By using the "database_default" collation,
--you can inherit collation from current database
CREATE TABLE #CT_dd_(c1 CHAR(5) COLLATE database_default)
SELECT collation
FROM tempdb..sysobjects so INNER JOIN tempdb..syscolumns sc ON so.id = sc.id
WHERE so.name like '%#CT_dd_%'
--Create temp table with SELECT INTO.
--Table will inherit *resultsets* collation
USE master
GO
SELECT * INTO #SI FROM TestDb..t1
SELECT collation
FROM tempdb..sysobjects so INNER JOIN tempdb..syscolumns sc ON so.id = sc.id
WHERE so.name like '%#SI%'
GO
--
Tibor Karaszi, SQL Server MVP
FAQ from Neil at: http://www.sqlserverfaq.com
Please reply to the newsgroup only, not by email.