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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With