Skip to main content
Tweeted twitter.com/StackDBAs/status/866675060643430400
edited tags
Link
Solomon Rutzky
  • 69.5k
  • 8
  • 155
  • 300
Source Link
Racer SQL
  • 7.5k
  • 14
  • 73
  • 136

Trigger to change Database collation on creation

I'm trying to create a Trigger, to alter collation of a database on its creation, but how can I catch the database name to use inside the trigger?

USE master
GO
CREATE TRIGGER trg_DDL_ChangeCOllationDatabase
ON ALL SERVER
FOR CREATE_DATABASE
AS
declare @databasename varchar(200)
set @databasename =db_name()
    ALTER DATABASE @databasename COLLATE xxxxxxxxxxxxxxxxxxx
GO

Obviously, this is not working.