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.
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?
That said, you can also use the following function HAS_PERMS_BY_NAME
:
SELECT HAS_PERMS_BY_NAME(db_name(), 'DATABASE', 'CREATE TABLE');
More information here:
http://msdn.microsoft.com/en-us/library/ms189802.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With