找出会话的默认 SQL Server 架构 [英] Find out default SQL Server schema for session

查看:33
本文介绍了找出会话的默认 SQL Server 架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道正在执行某些 DDL 的 SQL 脚本中当前的默认架构是什么.我不需要设置架构,但我确实需要将它的引用(名称或 ID)放入一个变量中.该脚本可能作为 Windows 登录名运行,因此以下内容还不够:

I have a requirement to know what the current default schema is in a SQL script that is doing some DDL. I don't need to set the schema, but I do need to get a reference to it (name or ID) into a variable. The script may be running as a windows login, so the following isn't sufficient:

SELECT name, default_schema_name 
FROM sys.database_principals 
WHERE type = 'S' and name = SYSTEM_USER --SYSTEM User won't be named as a principal

我曾想过在当前模式中创建一个随机命名的对象,然后在 information_schema 中查看其详细信息,但有人有更简洁的方法吗?

I've thought of doing it by creating a randomly named object in the current schema, and then looking at its details in the information_schema, but does anyone have a tidier way?

我在 SQL Server 2005 中工作.

I'm working in SQL Server 2005.

推荐答案

这个怎么样.

SELECT SCHEMA_NAME()

http://msdn.microsoft.com/en-us/library/ms175068.aspx

SCHEMA_NAME 将返回调用者默认架构的名称

SCHEMA_NAME will return the name of the default schema of the caller

或者SCHEMA_ID()

这篇关于找出会话的默认 SQL Server 架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆