T-SQL: Add group to each user database
Below is an example script which adds a windows domain group to each database, with the db_reader role.
I.T. minded
Below is an example script which adds a windows domain group to each database, with the db_reader role.
You may use the T-SQL code below to find the last logon dates for the SQL accounts.
The T-SQL query below will list the users configured within the database, and the permissions which this users has.
To identify the queries that are responsible for high-CPU activity currently, run the following statement: If queries aren’t driving the CPU at this moment, you can run the following statement to look for historical CPU-bound queries:
Well, SQL statements can use a log of log space, and you most probably want to find out which SQL statement is using all of your log space. The T-SQL code below will show you the SQL statements using the…
First off you don’t ever shrink a database file unless you known it won’t need the space back again. (There’s some caveats to that statement but it mostly holds true) If that’s the space the file has consumed generally that’s…
After a while,the msdb database can be overloaded with backup history, and clearing that history can be a pain. You can use the t-sql code below to clear the msdb backup history, in incremental steps of 1 week.
You can group datetime fields by year/month by using a simple ‘format’. Of course, there are other possibilities for doing this. See example below:
When SQL Server needs a database master key to decrypt or encrypt a key, SQL Server tries to decrypt the database master key with the service master key of the instance. If the decryption fails, SQL Server searches the credential…
It is possible that sql jobs are “hanging” in a suspended state. The SQL statements below will give you an indication on what the job is waiting.The first SQL statement will create a small stored procedure in the master database,…
If you are using SSMS 17 or 18, you have maybe noticed that the SSMS startup can be very very very very slow, which is annoying for everyone. There are 2 workaround, which could resolve this issue: Open Internet Explorer: Options…
The T-SQL code below lists the currently running SQL Agent jobs.
You can monitoring TEMPDB usage by using the following SQL statement.
The code below can be used to query the linked servers & the user assigned to it.
The SQL statement below will kill all sessions from a specific user, which wasn’t active the last hour.Of course, change ‘my_user’ with your preferred userid. If you want you can also uncomment the ‘program_name’ if you want to filter on…
Automatic seeding for SQL Always On it nice, but in case of big databases this can take some time. Of course, it can be annoying if something is running, and you don’t see the status of it. The query below…
On the distribution database, you can execute the statement below to get the sizes of the internal replication specific tables
You can use the code below on your distributor in order to check the backlog of the replication
You can use the t-sql code to resume/suspend all databases from the always on group.The code below will resume SQL data movement for all databases: The code below will suspend SQL data movement for all databases:
In a SQL Always On setup, the SQL agent jobs are not synced between the different nodes. This means you need to manually create them on the other nodes. For read-write jobs, you can only run them on the active…