Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two smiling suns equals one smiling sun?

Tags:

sql-server

How does SQL Server decide if two identifiers match? No matter what order I arrange the following statements, SQL Server will happily create the first one, then refuse to create any of the others saying they already exist.

create database [🌞]
go
create database [🌞🌞]
go
create database [ 🌞 🌞 ]
go
create database [🐱🐱🐱]
go
create database [🐱🐱]
go
create database [🐱]
go
create database [🌞🐱]
go
like image 702
David Dubois Avatar asked May 15 '19 19:05

David Dubois


1 Answers

How does SQL Server decide if two identifiers match?

Database Names are compared using the Server Collation. Inside a database the identifiers for Tables and other objects names are compared using the Database Collation.

The server collation is specified during SQL Server installation. Default server-level collation is SQL_Latin1_General_CP1_CI_AS.

For any two characters the collation determines which one is greater, or whether they are considered equal. So is 🌞 > 🐱, 🌞 < 🐱, or 🌞 = 🐱?

select 'match'
where N' 🌞 🌞 ' = N'🐱🐱🐱' collate SQL_Latin1_General_CP1_CI_AS

Matches, but

select 'match'
where N' 🌞 🌞 ' = N'🐱🐱🐱' collate Latin1_General_Bin 

doesn't.

like image 161
David Browne - Microsoft Avatar answered Nov 06 '22 23:11

David Browne - Microsoft