Monday, September 9, 2024

How do I find the largest tables in a SQL Server database?

 You can use the following query to find the largest tables by data size:

SELECT t.NAME AS TableName, p.rows AS RowCounts, SUM(a.total_pages) * 8 AS TotalSpaceKB, SUM(a.used_pages) * 8 AS UsedSpaceKB, (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB FROM sys.tables t INNER JOIN sys.indexes i ON t.OBJECT_ID = i.object_id INNER JOIN sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id INNER JOIN sys.allocation_units a ON p.partition_id = a.container_id WHERE t.NAME NOT LIKE 'dt%' AND i.OBJECT_ID > 255 GROUP BY t.Name, p.Rows ORDER BY TotalSpaceKB DESC;


This query returns the largest tables by row count and space usage.

How can I retrieve a list of all users in a specific SQL Server database?

 You can get the list of all users in a database using this query:

SELECT name AS Username FROM sys.database_principals WHERE type IN ('S', 'U') -- 'S' for SQL user, 'U' for Windows user AND name NOT LIKE '##%'; -- Exclude system users

This lists all users in the current database.

How can I find out the currently running queries in SQL Server?

 Use the following query to find currently running queries:

SELECT r.session_id, r.start_time, s.text AS query_text, r.status, r.command, r.total_elapsed_time FROM sys.dm_exec_requests r CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) s;

This returns details about all currently running queries, including the session ID, query text, and execution status.

How do I check the status of a SQL Server transaction?

 You can check the status of running transactions using this query:

SELECT session_id, transaction_id, database_id, transaction_begin_time, transaction_state, transaction_status

FROM sys.dm_tran_active_transactions;

This query gives you information about active transactions in SQL Server.

How do I list all tables in a specific database?

 You can use the following query to list all tables in the current database:

SELECT TABLE_NAME 

FROM INFORMATION_SCHEMA.TABLES

WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_CATALOG = 'YourDatabaseName';

This query returns the names of all base tables in the specified database.


How can I check the size of a specific database in SQL Server?

 You can check the size of a database using the following query:

EXEC sp_spaceused;

Or, for a specific database:

USE YourDatabaseName;

EXEC sp_spaceused;

This command returns the database size, reserved space, unallocated space, and more.

How do I find the SPID (Session Process ID) for a specific database in SQL Server?

 SELECT 

    es.session_id AS SPID, 

    es.login_name, 

    es.status, 

    es.host_name, 

    es.program_name, 

    es.database_id, 

    DB_NAME(es.database_id) AS database_name,

    ec.client_net_address,

    er.wait_type, 

    er.wait_time, 

    er.blocking_session_id

FROM sys.dm_exec_sessions es

LEFT JOIN sys.dm_exec_connections ec ON es.session_id = ec.session_id

LEFT JOIN sys.dm_exec_requests er ON es.session_id = er.session_id

WHERE es.database_id = DB_ID('YourDatabaseName');

------------------------------------------------------------------------------------

kill SSID

Monday, September 2, 2024

The breakpoint will not currently be hit. No symbols have been loaded for this document.

If you are getting this error breakpoint in view then there is some error in view or some property name is wrong. Then check and fix all lines. After correction it will work.

Thursday, August 29, 2024

An unhandled exception of type 'System.TypeInitializationException' occurred in System.ServiceModel.dll. Additional information: The type initializer for 'System.ServiceModel.Diagnostics.TraceUtility' threw an exception.

 Common Causes:

  • Configuration Errors: Issues in your WCF configuration (e.g., app.config or web.config) could trigger this exception. Check that your configuration files are correctly set up, especially sections related to diagnostics and tracing.

  • Missing or Corrupt DLLs: If a required DLL (e.g., System.ServiceModel.dll) is missing or corrupt, the type initializer might fail. Ensure that all necessary assemblies are present and correctly referenced in your project.

  • Permissions Issues: The TraceUtility class may attempt to access system resources, such as event logs or trace files. If the application lacks the necessary permissions, it could cause this exception. Ensure your application has the appropriate permissions to access these resources.