我需要通过变量创建整理或在创建数据库后更改它 所以试试这个:
USE master;
GO
IF DB_ID (N'DATA') IS NOT NULL
DROP DATABASE DATA;
GO
DECLARE @COLLATE Nvarchar(50) SET @COLLATE ='Latin1_General_100_CS_AS_SC'
CREATE DATABASE DATA
COLLATE Latin1_General_100_CS_AS_SC;
--COLLATE @COLLATE;
GO
SELECT name, collation_name
FROM sys.databases
WHERE name = N'DATA';
--or
ALTER DATABASE [DATA] COLLATE @COLLATE
SELECT name, collation_name
FROM sys.databases
WHERE name = N'DATA';
答案 0 :(得分:2)
这是一个可以使用的SQL脚本
USE master;
GO
IF DB_ID (N'DATA') IS NOT NULL
DROP DATABASE DATA;
GO
DECLARE @COLLATE Nvarchar(50)
SET @COLLATE ='Latin1_General_100_CS_AS_SC'
DECLARE @SQL nvarchar(max)
set @SQL = 'CREATE DATABASE DATA COLLATE ' + @COLLATE;
exec sp_executeSQL @SQL
请注意,因为它运行DROP数据库命令
有关building dynamic SQL的更多信息,请查看上述文章