Note: I'm not going to comment on the query itself, but I'm going to instead talk about something which also impacts this, considering the size of this query.
Some basic math, assuming the average size of data inside varchar columns is 30 characters and columns are roughly split between the 3 types:
101 columns * ((30+8+4)/3) = 14 bytes per column * 4,000,...
I assume by everything you mean db_owner rights. Not Sysadmin rights.
If you can't trust them not to drop a database, they should not have access to most things you can do with Sysadmin.
What you want is described in the answer here https://dba.stackexchange.com/a/163437/21924
So in effect, you can create a user that has all the rights of db_owner ...
NULL is not a value of the column but an internal metadata flag showing the column has no value. So duplicating this in user space by adding another flag column is a waste. NULL is a well-supported part of the relational model. Use it for its intended purpose.
This builds the table you are looking for:
ImportantDates AS (
SELECT * FROM (
This approach assumes Important Dates are continous
A better approach would be to build from start dates
to ensure that it s.
Which system catalog view has the create_date of a database which name was modified? Or an alternative reliable method if such view doesn't exist.
You're correct in your assessment of create_date in sys.databases, which is confirmed by the documentation:
Date the database was created or renamed.
So the create_date is the ideal value to use as the end ...
I prefer to use db_owner Not using Sysadmin.
And use Server Trigger to prevent delete database accidentally Like this :
To create a DDL trigger with server scope (ON ALL SERVER) or a logon trigger, requires CONTROL SERVER permission on the server