Count the Number of Tables in a SQL Server Database [duplicate]

You can use INFORMATION_SCHEMA.TABLES to retrieve information about your database tables. As mentioned in the Microsoft Tables Documentation: INFORMATION_SCHEMA.TABLES returns one row for each table in the current database for which the current user has permissions. The following query, therefore, will return the number of tables in the specified database: USE MyDatabase SELECT COUNT(*) FROM … Read more

How to remove cached server names from the Connect to Server dialog?

As of SQL Server 2012 you no longer have to go through the hassle of deleting the bin file (which causes other side effects). You should be able to press the Delete key within the MRU list of the Server Name dropdown in the Connect to Server dialog. This is documented in this Connect item … Read more

How to subtract 30 days from the current date using SQL Server

You can convert it to datetime, and then use DATEADD(DAY, -30, date). See here. edit I suspect many people are finding this question because they want to substract from current date (as is the title of the question, but not what OP intended). The comment of munyul below answers that question more specifically. Since comments … Read more

SQL Server 2012 can’t start because of a login failure

The answer to this may be identical to the problem with full blown SQL Server (NTService\MSSQLSERVER) and this is to reset the password. The ironic thing is, there is no password. Steps are: Right click on the Service in the Services mmc Click Properties Click on the Log On tab The password fields will appear … Read more

Last executed queries for a specific database

This works for me to find queries on any database in the instance. I’m sysadmin on the instance (check your privileges): SELECT deqs.last_execution_time AS [Time], dest.text AS [Query], dest.* FROM sys.dm_exec_query_stats AS deqs CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest WHERE dest.dbid = DB_ID(‘msdb’) ORDER BY deqs.last_execution_time DESC This is the same answer that Aaron Bertrand provided … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)