Thursday, April 09, 2026

Rebuild Index Scripts

 USE DatabaseName

go
 'NJW23987hxJKL969#ghf0%94467GRkjg5k3fd117r$$#1946kcj$n44nhdlj'  
X7lLh0FoQYLMt01gaTJD

DECLARE @Database NVARCHAR(255)  
DECLARE @Table NVARCHAR(255)  
DECLARE @cmd NVARCHAR(1000)  
DECLARE DatabaseCursor CURSOR READ_ONLY FOR  
SELECT name FROM master.sys.databases  
--WHERE name NOT IN ('master','msdb','tempdb','model','distribution')  -- databases to exclude
WHERE name IN ('VesselRoutes' ) -- use this to select specific databases and comment out line above
AND state = 0 -- database is online
AND is_in_standby = 0 -- database is not read only for log shipping
ORDER BY 1  

OPEN DatabaseCursor  

FETCH NEXT FROM DatabaseCursor INTO @Database  
WHILE @@FETCH_STATUS = 0  
BEGIN  

   SET @cmd = 'DECLARE TableCursor CURSOR READ_ONLY FOR SELECT ''['' + table_catalog + ''].['' + table_schema + ''].['' +  
   table_name + '']'' as tableName FROM [' + @Database + '].INFORMATION_SCHEMA.TABLES WHERE table_type = ''BASE TABLE'''  

   -- create table cursor  
   EXEC (@cmd)  
   OPEN TableCursor  

   FETCH NEXT FROM TableCursor INTO @Table  
   WHILE @@FETCH_STATUS = 0  
   BEGIN
      BEGIN TRY  
         SET @cmd = 'ALTER INDEX ALL ON ' + @Table + ' REBUILD'
         --PRINT @cmd -- uncomment if you want to see commands
         EXEC (@cmd)
      END TRY
      BEGIN CATCH
         PRINT '---'
         PRINT @cmd
         PRINT ERROR_MESSAGE()
         PRINT '---'
      END CATCH

      FETCH NEXT FROM TableCursor INTO @Table  
   END  

   CLOSE TableCursor  
   DEALLOCATE TableCursor  

   FETCH NEXT FROM DatabaseCursor INTO @Database  
END  
CLOSE DatabaseCursor  
DEALLOCATE DatabaseCursor

Tuesday, March 24, 2026

SQL Server 2025 Platform Architecture

SQL Server 2025 (17.x) is a major leap forward, primarily because it shifts the database from a "storage engine" to an AI-ready data platform. It integrates features that previously required external services—like vector searches, machine learning, and advanced text processing—directly into the T-SQL engine.

Here is a breakdown of the most significant advancements in this release:

1. Built-in AI and Vector Search

The standout feature of 2025 is native AI integration. You no longer need to export data to specialized vector databases to build "intelligent" apps like recommendation engines or chatbots.

  • Native VECTOR Data Type: Allows you to store embeddings (numerical representations of meaning) directly.

  • DiskANN Indexing: A state-of-the-art vector indexing technology that enables lightning-fast "nearest neighbor" searches even on massive datasets.

  • T-SQL Model Management: You can now register and call external AI models (like Azure OpenAI or Ollama) directly from a SQL query using sp_invoke_external_rest_endpoint.

2. Modern Developer Productivity

Microsoft has addressed several long-standing "wish list" items for developers, making T-SQL much more flexible.

  • Native JSON Type: Unlike previous versions that stored JSON as strings, 2025 uses a native binary format. This makes parsing faster, storage smaller, and allows for direct indexing on JSON fields.

  • Regular Expressions (RegEx): After decades of requests, functions like REGEXP_LIKE and REGEXP_REPLACE are finally built into T-SQL, eliminating the need for complex workarounds or CLR assemblies for string validation.

  • Change Event Streaming (CES): You can now stream data changes directly to Azure Event Hubs in real-time, simplifying the creation of event-driven architectures.

3. "Zero-ETL" and Cloud Connectivity

The "choice of environment" you mentioned is realized through deeper integration with Microsoft Fabric and Azure Arc.

  • Fabric Mirroring: This allows your on-premises SQL Server data to be mirrored into Microsoft Fabric's "OneLake" in near real-time. This provides a "Zero-ETL" experience, meaning you can run heavy analytics in the cloud without setting up complex data pipelines.

  • Managed Identities (Entra ID): You can now use Azure Managed Identities for on-premises servers. This means your SQL Server can authenticate to Azure services (like Blob Storage for backups) without you ever having to manage or rotate passwords.

4. Performance and Scalability Boosts

SQL Server 2025 brings several "cloud-born" features from Azure SQL Database to the on-premises engine.

  • Optimized Locking: Uses a new "Transaction ID" (TID) locking mechanism that significantly reduces memory consumption and blocking for concurrent transactions.

  • Standard Edition Upgrades: Microsoft has increased the limits for the Standard Edition to 32 cores and 256 GB of RAM, acknowledging that modern hardware has outpaced the old 2022 limits.

  • Zstandard (ZSTD) Compression: A new backup compression algorithm that offers better ratios and faster performance than the older default compression