The query below can retrieve database id by supplying the database name
-- Show database id using system view
SELECT
database_id
FROM
sys.databases
WHERE
name
=
'<db_name>'
;
Welcome to SQLDBANow.com! This blog, created by Bandaru Ajeyudu, is dedicated to learning and sharing knowledge about SQL DBA and Azure SQL. Join us as we explore insights, tips, and best practices in the world of SQL Database Administration and Azure SQL.
The query below can retrieve database id by supplying the database name
-- Show database id using system view
SELECT
database_id
FROM
sys.databases
WHERE
name
=
'<db_name>'
;
What Is Index Fragmentation?
Over time, as records are inserted, updated, and deleted, your tables and indexes become fragmented. This fragmentation can lead to poor performance of not only your SELECT queries, but also your INSERT, UPDATE, and DELETE operations.
How Do I Find Index Fragmentation?
Index fragmentation can be found by querying the built in sys.dm_db_index_physical_stats DMV. To get readable, useful information you’ll also need to join your query to other DMVs such as sys.indexes and sys.tables. Below is a simple query that will provide a list of indexes, fragmentation percentage, and record counts for each table in a database.