如何检测我是否具有CREATE TABLE权限? [英] How can I detect whether I have CREATE TABLE permission?

查看:154
本文介绍了如何检测我是否具有CREATE TABLE权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式检测当前用户在当前数据库中是否具有CREATE TABLE权限?

How can I programmatically detect whether the current user has CREATE TABLE permissions in the current database?

我正在编写一个工具,该工具将进行一些冗长的处理,然后创建数据库表以保存结果.我只想在处理运行完成时创建表.但是,如果用户无法创建表,那么花时间进行处理就没有意义了.我想检测权限问题并快速失败.

I'm writing a tool that will do some lengthy processing, and then create database tables to save the results. I only want to create the tables if the processing runs to completion. But if the user won't be able to create the tables, there's no point spending time processing. I'd like to detect the permission issue and fail fast.

这将来自C#应用程序,我无法假定将安装任何特殊的库,这可能排除了SQL-DMO和SMO.如果有一种使用T-SQL查询/脚本检查权限的简便方法,那将是理想的选择.

This will be from a C# application, and I can't assume that any special libraries will be installed, which probably rules out SQL-DMO and SMO. If there's an easy way to check permissions with a T-SQL query/script, that would be ideal.

推荐答案

为什么不首先创建表,如果失败,就不做进一步了吗?

Why not create the table first, and if that fails, go no further?

也就是说,您还可以使用以下功能HAS_PERMS_BY_NAME:

That said, you can also use the following function HAS_PERMS_BY_NAME:

SELECT HAS_PERMS_BY_NAME(db_name(), 'DATABASE', 'CREATE TABLE');

更多信息在这里:

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

这篇关于如何检测我是否具有CREATE TABLE权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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