If you copy (backup/restore) a database from system A to system B, it is possible that the SQL users won’t be able login and this because the GUID/SID of the users on system A doesn’t match the GUID/SID of system B. It is using the EXEC sp_change_users_login ‘Auto_Fix’, which inks a user entry in the sys.database_principals system catalog view in
Not all SQL scripts should be short 😉 The T-SQL code below will list the SQL Agent job history.
SQL server is of course caching data, in order to minimize access to disks. Sometimes you want to clear that memory, for testing purposes for example. You can use DBCC commands in order to clear the system / proc / session cache. See the SQL below:
When you are looking for the creation date/time of certain tables, you can easily find that in the sys.tables.You can use the code below in order to list all tables, and the creation date of those tables.
Sometimes you need to know when a SQL login was created. The SQL code below will list the SQL logins, when this was created, and if this is enabled or disabled.
The t-sql code below will give you the top 10 most CPU consuming SQL statements in your database, sorted by CPU time.
Disk I/O is most of the time the bottleneck of your SQL database, even when using SSD. The SQL statement below will show you the most heavy disk I/O statements, which you should improve.
The code below will give you the top 10 most executed stored procedures in your database, sorted by execution count.
Interested to see how long your SQL server agent is up and running, or you want to see if that agent is operational? You can use the t-sql code below to find out:
The SQL statement below will give you the top 100 longest running SQL statements in your database, sorted by duration.