且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

DDL Trigeer在SQL Server 2005中创建数据库时创建表

更新时间:2023-02-07 11:33:35

我在这里假设您遇到的问题是在创建新数据库时触发触发器,但不是在新数据库的上下文中运行而是在master数据库下运行(因此尝试创建表)在师父)?

我必须做类似的事情,除了它是每个数据库的设置权限.为了完成它,我必须使用数据库名称来构建动态查询.遍历每个检查,查看数据库是否具有已创建的对象,如果没有,则创建它们.粗略地,我的任务是在所有数据库中检查和应用需要的地方.因此,我并不仅针对新数据库,还针对所有数据库.它运作良好,并确保权限始终正确.

I am assuming here the problem you are running into is that the trigger gets fired whe you create a new database but instead of running under the context of the new database it runs under the master database (thus trying to create your tables in Master)?

I had to do a similar thing, except it was setup permissions on each database. In order to acomplish it, I had to build dynamic queries with the database names. Loop through each check and see if the database had the obects already created if not then create them. Of coarse my task was to check and apply the perissions where needed against all databases. So I didnt target just the new database, but all databases. It works well and insures the persmissions are always correct.

Make sense?


罗希特,好消息.很高兴能够提供帮助.
Hi Rohit, that''s great news. Glad to have been able to help.