请确认 TempDB 中整理 database_default 的行为

Please confirm behaviour of collate database_default in TempDB

我不确定在使用

创建临时 table 时使用哪种排序规则
create table #temp 
( object varchar(16) COLLATE database_default
, lev int ) 

例如这是使用 TempDB 排序规则还是用户数据库排序规则?

它使用了tempdb的排序规则。我通过将我的一个用户数据库的排序规则设置为 Albanian_BIN(值得注意的是,这与 tempdb 的排序规则不同)和 运行:

在我的本地计算机上进行了测试
create table #foo (a varchar(100), b nvarchar(100));
select collation_name
from tempdb.sys.columns
where OBJECT_ID = object_id('tempdb.dbo.#foo');

返回两行,都反映了 tempdb 的排序规则。

根据 Ben 的回答,我做了以下操作。这清楚地表明使用了用户数据库的排序规则。

/* Find Collation of SQL Server Database */

SELECT DATABASEPROPERTYEX('objective', 'Collation')
-- Latin1_General_BIN2

SELECT DATABASEPROPERTYEX('tempDB', 'Collation')
-- SQL_Latin1_General_CP1_CI_AS

GO

/* Find Collation of SQL Server Database Table Column */

USE objective
GO

create table #temp
( id int
, word varchar(10))

select collation_name
from tempdb.sys.columns
where OBJECT_ID = object_id('tempdb.dbo.#temp');
-- SQL_Latin1_General_CP1_CI_AS


create table #temp2
( id int
, word varchar(10) COLLATE database_default)

select collation_name
from tempdb.sys.columns
where OBJECT_ID = object_id('tempdb.dbo.#temp2');
-- Latin1_General_BIN2