<script type="application/ld+json">{"@context":"http://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://www.simcentric.com/tc/"},{"@type":"ListItem","position":2,"name":"哪些技術可以提高SQL Server的效率?","item":"https://www.simcentric.com/tc/hong-kong-dedicated-server-tc/what-techniques-boost-sql-server-efficiency/"}]}</script> {"id":14936,"date":"2024-08-22T12:09:21","date_gmt":"2024-08-22T04:09:21","guid":{"rendered":"https:\/\/www.simcentric.com\/uncategorized-tc\/what-techniques-boost-sql-server-efficiency\/"},"modified":"2024-08-22T12:14:52","modified_gmt":"2024-08-22T04:14:52","slug":"what-techniques-boost-sql-server-efficiency","status":"publish","type":"post","link":"https:\/\/www.simcentric.com\/tc\/hong-kong-dedicated-server-tc\/what-techniques-boost-sql-server-efficiency\/","title":{"rendered":"\u54ea\u4e9b\u6280\u8853\u53ef\u4ee5\u63d0\u9ad8SQL Server\u7684\u6548\u7387?"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><p>[vc_row el_class=&#8221;blog-detail-section&#8221;][vc_column][vc_column_text]<\/p>\n<p>\u5728\u7576\u4eca\u6578\u64da\u9a45\u52d5\u7684\u4e16\u754c\u4e2d,\u512a\u5316<strong><a href=\"https:\/\/www.simcentric.com\/tc\/hong-kong-dedicated-server\/what-is-the-sql-server\/\" target=\"_blank\" rel=\"noopener\">SQL Server<\/a><\/strong>\u6027\u80fd\u4e26\u5229\u7528\u5176\u9ad8\u7d1a\u529f\u80fd\u5c0d\u4f01\u696d\u4fdd\u6301\u7af6\u722d\u512a\u52e2\u81f3\u95dc\u91cd\u8981,\u7279\u5225\u662f\u5c0d\u65bc<strong><a href=\"https:\/\/www.simcentric.com\/tc\/products\/dedicated-server-hk\/\" target=\"_blank\" rel=\"noopener\">\u7368\u7acb\u4f3a\u670d\u5668<\/a><\/strong>\u7528\u6236\u800c\u8a00\u3002\u672c\u6587\u6df1\u5165\u63a2\u8a0e\u4e86\u8907\u96dc\u7684SQL Server\u512a\u5316\u6280\u8853\u548c\u61c9\u7528,\u91cd\u9ede\u95dc\u6ce8\u9ad8\u53ef\u7528\u6027\u89e3\u6c7a\u65b9\u6848\u3001\u6578\u64da\u9077\u79fb\u7b56\u7565\u3001\u5831\u8868\u670d\u52d9\u4ee5\u53ca\u6709\u6548\u7684\u76e3\u63a7\u548c\u6545\u969c\u6392\u9664\u5be6\u8e10\u3002<\/p>\n<p>[\/vc_column_text][\/vc_column][\/vc_row][vc_row el_class=&#8221;blog-detail-section&#8221;][vc_column][vc_column_text]<\/p>\n<h2>1. SQL Server\u4e2d\u7684\u9ad8\u53ef\u7528\u6027\u89e3\u6c7a\u65b9\u6848<\/h2>\n<p>\u5728\u73fe\u4ee3\u5546\u696d\u74b0\u5883\u4e2d,\u78ba\u4fdd\u95dc\u9375\u6578\u64da\u7684\u6301\u7e8c\u8a2a\u554f\u81f3\u95dc\u91cd\u8981\u3002SQL Server\u63d0\u4f9b\u4e86\u5e7e\u7a2e\u9ad8\u53ef\u7528\u6027\u89e3\u6c7a\u65b9\u6848,\u4ee5\u6700\u5927\u9650\u5ea6\u5730\u6e1b\u5c11\u505c\u6a5f\u6642\u9593\u4e26\u4fdd\u6301\u6578\u64da\u7684\u53ef\u8a2a\u554f\u6027\u3002<\/p>\n<h3>1.1 AlwaysOn\u53ef\u7528\u6027\u7fa4\u7d44<\/h3>\n<p>AlwaysOn\u53ef\u7528\u6027\u7fa4\u7d44\u70ba\u6578\u64da\u5eab\u7d1a\u9ad8\u53ef\u7528\u6027\u548c\u707d\u96e3\u5fa9\u539f\u63d0\u4f9b\u4e86\u5f37\u5927\u7684\u89e3\u6c7a\u65b9\u6848\u3002\u4ee5\u4e0b\u662f\u5275\u5efa\u53ef\u7528\u6027\u7fa4\u7d44\u7684\u57fa\u672cT-SQL\u8173\u672c:<\/p>\n<pre><code>-- Create the availability group\r\nCREATE AVAILABILITY GROUP [AG_PrimaryDatabase]\r\nFOR DATABASE [PrimaryDatabase]\r\nREPLICA ON \r\n'PrimaryServer' WITH (ENDPOINT_URL = 'TCP:\/\/PrimaryServer:5022',\r\n    FAILOVER_MODE = AUTOMATIC,\r\n    AVAILABILITY_MODE = SYNCHRONOUS_COMMIT,\r\n    BACKUP_PRIORITY = 50,\r\n    SECONDARY_ROLE(ALLOW_CONNECTIONS = ALL)),\r\n'SecondaryServer' WITH (ENDPOINT_URL = 'TCP:\/\/SecondaryServer:5022',\r\n    FAILOVER_MODE = AUTOMATIC,\r\n    AVAILABILITY_MODE = SYNCHRONOUS_COMMIT,\r\n    BACKUP_PRIORITY = 50,\r\n    SECONDARY_ROLE(ALLOW_CONNECTIONS = ALL));\r\n\r\n-- Join the secondary replica to the availability group\r\nALTER AVAILABILITY GROUP [AG_PrimaryDatabase] JOIN;\r\n\r\n-- Create a listener for the availability group\r\nALTER AVAILABILITY GROUP [AG_PrimaryDatabase]\r\nADD LISTENER 'AGListener' (\r\n    WITH IP\r\n    ((N'10.0.0.30', N'255.255.255.0')\r\n    )\r\n    , PORT=1433);<\/code><\/pre>\n<p>\u9019\u7a2e\u914d\u7f6e\u78ba\u4fdd\u4e86\u4e3b\u4f3a\u670d\u5668\u548c\u8f14\u52a9\u4f3a\u670d\u5668\u4e4b\u9593\u7684\u81ea\u52d5\u6545\u969c\u8f49\u79fb\u548c\u540c\u6b65\u6578\u64da\u8907\u88fd\u3002<\/p>\n<h3>1.2 \u6545\u969c\u8f49\u79fb\u53e2\u96c6\u57f7\u884c\u500b\u9ad4(FCI)<\/h3>\n<p>\u6545\u969c\u8f49\u79fb\u53e2\u96c6\u57f7\u884c\u500b\u9ad4\u63d0\u4f9b\u57f7\u884c\u500b\u9ad4\u7d1a\u9ad8\u53ef\u7528\u6027\u3002\u8981\u8a2d\u7f6eFCI,\u60a8\u9700\u8981\u914d\u7f6eWindows Server\u6545\u969c\u8f49\u79fb\u53e2\u96c6(WSFC),\u7136\u5f8c\u5c07SQL Server\u5b89\u88dd\u70ba\u53e2\u96c6\u89d2\u8272\u3002\u4ee5\u4e0b\u662f\u5c07SQL Server\u8cc7\u6e90\u6dfb\u52a0\u5230\u73fe\u6709WSFC\u7684PowerShell\u8173\u672c:<\/p>\n<pre><code>Import-Module FailoverClusters\r\n\r\nAdd-ClusterResource -Name \"SQL Server\" -Group \"SQL Server Group\" -ResourceType \"SQL Server\"\r\n\r\n# Set dependencies\r\nAdd-ClusterResourceDependency -Resource \"SQL Server\" -Provider \"SQL Network Name\"\r\nAdd-ClusterResourceDependency -Resource \"SQL Server\" -Provider \"SQL IP Address\"\r\n\r\n# Configure the SQL Server resource\r\nSet-ClusterParameter -Name VirtualServerName -Value \"SQLCLUSTER\" -InputObject (Get-ClusterResource \"SQL Server\")\r\nSet-ClusterParameter -Name InstanceName -Value \"MSSQLSERVER\" -InputObject (Get-ClusterResource \"SQL Server\")\r\n\r\n# Bring the SQL Server resource online\r\nStart-ClusterResource \"SQL Server\"<\/code><\/pre>\n<h3>1.3 \u6578\u64da\u5eab\u93e1\u50cf<\/h3>\n<p>\u96d6\u7136\u6578\u64da\u5eab\u93e1\u50cf\u6b63\u5728\u88ab\u53ef\u7528\u6027\u7fa4\u7d44\u6240\u53d6\u4ee3,\u4f46\u5728\u67d0\u4e9b\u74b0\u5883\u4e2d\u4ecd\u5728\u4f7f\u7528\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u8a2d\u7f6e\u6578\u64da\u5eab\u93e1\u50cf:<\/p>\n<pre><code>-- On the principal server\r\nALTER DATABASE [YourDatabase] SET RECOVERY FULL;\r\nBACKUP DATABASE [YourDatabase] TO DISK = 'C:\\YourDatabase.bak';\r\nBACKUP LOG [YourDatabase] TO DISK = 'C:\\YourDatabase_log.bak';\r\n\r\n-- On the mirror server\r\nRESTORE DATABASE [YourDatabase] FROM DISK = 'C:\\YourDatabase.bak'\r\nWITH NORECOVERY;\r\nRESTORE LOG [YourDatabase] FROM DISK = 'C:\\YourDatabase_log.bak'\r\nWITH NORECOVERY;\r\n\r\n-- On the principal server\r\nALTER DATABASE [YourDatabase] SET PARTNER = 'TCP:\/\/MirrorServer:5022';\r\n\r\n-- On the mirror server\r\nALTER DATABASE [YourDatabase] SET PARTNER = 'TCP:\/\/PrincipalServer:5022';<\/code><\/pre>\n<p>[\/vc_column_text][\/vc_column][\/vc_row][vc_row el_class=&#8221;blog-detail-section&#8221;][vc_column][vc_column_text]<\/p>\n<h2>2. \u6578\u64da\u9077\u79fb\u6280\u8853<\/h2>\n<p>\u5728\u5347\u7d1a\u7cfb\u7d71\u3001\u6574\u5408\u6578\u64da\u5eab\u6216\u9077\u79fb\u5230\u96f2\u74b0\u5883\u6642,\u6709\u6548\u7684\u6578\u64da\u9077\u79fb\u81f3\u95dc\u91cd\u8981\u3002SQL Server\u63d0\u4f9b\u4e86\u5404\u7a2e\u5de5\u5177\u548c\u6280\u8853,\u7528\u65bc\u7121\u7e2b\u6578\u64da\u9077\u79fb\u3002<\/p>\n<h3>2.1 SQL Server\u9077\u79fb\u52a9\u624b(SSMA)<\/h3>\n<p>SSMA\u4fbf\u65bc\u5f9e\u5404\u7a2e\u6578\u64da\u5eab\u5e73\u53f0\u9077\u79fb\u5230SQL Server\u3002\u96d6\u7136\u5b83\u662f\u4e00\u500bGUI\u5de5\u5177,\u4f46\u60a8\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4\u884c\u64cd\u4f5c\u81ea\u52d5\u5316SSMA:<\/p>\n<pre><code>SSMAforDB2Console.exe \/s:scriptfile.xml \/c:commandfile.xml \/v:verbose<\/code><\/pre>\n<p>XML\u6a94\u6848\u5206\u5225\u5305\u542b\u9077\u79fb\u8a2d\u7f6e\u548c\u547d\u4ee4\u3002<\/p>\n<h3>2.2 \u6279\u91cf\u8907\u88fd\u7a0b\u5e8f(BCP)<\/h3>\n<p>BCP\u5c0d\u65bc\u79fb\u52d5\u5927\u91cf\u6578\u64da\u975e\u5e38\u9ad8\u6548\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528BCP\u5c0e\u51fa\u6578\u64da\u7684\u793a\u4f8b:<\/p>\n<pre><code>bcp \"SELECT * FROM SourceDB.dbo.Table\" queryout \"C:\\ExportedData.txt\" -c -T<\/code><\/pre>\n<p>\u5c0e\u5165\u6578\u64da:<\/p>\n<pre><code>bcp TargetDB.dbo.Table in \"C:\\ExportedData.txt\" -c -T<\/code><\/pre>\n<h3>2.3 SQL Server\u6574\u5408\u670d\u52d9(SSIS)<\/h3>\n<p>SSIS\u70ba\u8907\u96dc\u7684\u6578\u64da\u9077\u79fb\u63d0\u4f9b\u4e86\u5f37\u5927\u7684ETL\u5de5\u5177\u3002\u4ee5\u4e0b\u662f\u7528\u65bc\u6578\u64da\u50b3\u8f38\u7684SSIS\u5305\u8173\u672c\u4efb\u52d9\u793a\u4f8b:<\/p>\n<pre><code>using System;\r\nusing System.Data;\r\nusing Microsoft.SqlServer.Dts.Runtime;\r\nusing System.Windows.Forms;\r\n\r\npublic void Main()\r\n{\r\n    string sourceConnectionString = \"Data Source=SourceServer;Initial Catalog=SourceDB;Integrated Security=SSPI;\";\r\n    string destinationConnectionString = \"Data Source=DestServer;Initial Catalog=DestDB;Integrated Security=SSPI;\";\r\n    string query = \"SELECT * FROM SourceTable\";\r\n\r\n    using (SqlConnection sourceConnection = new SqlConnection(sourceConnectionString))\r\n    using (SqlConnection destinationConnection = new SqlConnection(destinationConnectionString))\r\n    {\r\n        sourceConnection.Open();\r\n        destinationConnection.Open();\r\n\r\n        using (SqlCommand command = new SqlCommand(query, sourceConnection))\r\n        using (SqlDataReader reader = command.ExecuteReader())\r\n        using (SqlBulkCopy bulkCopy = new SqlBulkCopy(destinationConnection))\r\n        {\r\n            bulkCopy.DestinationTableName = \"DestinationTable\";\r\n            bulkCopy.WriteToServer(reader);\r\n        }\r\n    }\r\n\r\n    Dts.TaskResult = (int)ScriptResults.Success;\r\n}<\/code><\/pre>\n<p>[\/vc_column_text][\/vc_column][\/vc_row][vc_row el_class=&#8221;blog-detail-section&#8221;][vc_column][vc_column_text]<\/p>\n<h2>3. SQL Server\u5831\u8868\u670d\u52d9(SSRS)\u61c9\u7528<\/h2>\n<p>SSRS\u70ba\u5728SQL Server\u74b0\u5883\u4e2d\u5275\u5efa\u548c\u7ba1\u7406\u5831\u8868\u63d0\u4f9b\u4e86\u5168\u9762\u7684\u5e73\u53f0\u3002<\/p>\n<h3>3.1 \u5275\u5efa\u52d5\u614b\u5831\u8868<\/h3>\n<p>\u4f7f\u7528\u5831\u8868\u751f\u6210\u5668\u6216Visual Studio\u5275\u5efa\u52d5\u614b\u5831\u8868\u3002\u4ee5\u4e0b\u662f\u53c3\u6578\u5316\u5831\u8868\u7684\u793a\u4f8bSQL\u67e5\u8a62:<\/p>\n<pre><code>SELECT \r\n    OrderDate,\r\n    ProductName,\r\n    Quantity,\r\n    UnitPrice,\r\n    (Quantity * UnitPrice) AS TotalSale\r\nFROM \r\n    Sales.OrderDetails od\r\n    JOIN Sales.Orders o ON od.OrderID = o.OrderID\r\n    JOIN Production.Products p ON od.ProductID = p.ProductID\r\nWHERE \r\n    OrderDate BETWEEN @StartDate AND @EndDate\r\n    AND ProductCategoryID = @CategoryID<\/code><\/pre>\n<h3>3.2 \u5c07\u5831\u8868\u90e8\u7f72\u5230SSRS<\/h3>\n<p>\u4f7f\u7528Web\u9580\u6236\u6216PowerShell\u90e8\u7f72\u5831\u8868\u3002\u4ee5\u4e0b\u662f\u7528\u65bc\u90e8\u7f72\u5831\u8868\u7684PowerShell\u8173\u672c:<\/p>\n<pre><code>$reportServerUri = \"http:\/\/your-server\/reportserver\"\r\n$reportPath = \"\/Folder\/ReportName\"\r\n$reportDefinition = Get-Content \"C:\\Reports\\YourReport.rdl\"\r\n\r\n$proxy = New-WebServiceProxy -Uri \"$reportServerUri\/ReportService2010.asmx\" -UseDefaultCredential\r\n$type = $proxy.GetType().Namespace\r\n\r\n$dataSourceReference = New-Object (\"$type.DataSourceReference\")\r\n$dataSourceReference.Reference = \"\/Datasources\/YourDataSource\"\r\n\r\n$properties = New-Object (\"$type.Property[]\") 1\r\n$properties[0] = New-Object (\"$type.Property\")\r\n$properties[0].Name = \"DataSourceReference\"\r\n$properties[0].Value = $dataSourceReference.Reference\r\n\r\n$proxy.CreateCatalogItem(\"Report\", $reportName, $reportPath, $true, $reportDefinition, $properties, [ref]$warnings)<\/code><\/pre>\n<h3>3.3 \u8a08\u5283\u548c\u8a02\u95b1<\/h3>\n<p>\u8a2d\u7f6e\u5831\u8868\u8a02\u95b1\u4ee5\u5be6\u73fe\u81ea\u52d5\u4ea4\u4ed8\u3002\u4ee5\u4e0b\u662f\u5275\u5efa\u6578\u64da\u9a45\u52d5\u8a02\u95b1\u7684T-SQL\u8173\u672c:<\/p>\n<pre><code>DECLARE @SubscriptionID uniqueidentifier\r\nEXEC msdb.dbo.sp_add_subscription\r\n    @report_id = '5741DF42-FEA2-4F74-AAAA-12345D4E217C',\r\n    @subscription_id = @SubscriptionID OUTPUT,\r\n    @owner_id = '1234ABCD-12AB-12AB-12AB-12345678ABCD',\r\n    @report_name = 'SalesReport',\r\n    @subscriber_description = 'Data-Driven Subscription',\r\n    @datasource_name = 'Subscribers',\r\n    @query = 'SELECT Email, Name FROM Subscribers WHERE Active = 1',\r\n    @notify_fields_type = 1,\r\n    @notify_fields = 'Email',\r\n    @delivery_extension = 'Report Server Email',\r\n    @render_format = 'PDF'\r\n\r\nEXEC msdb.dbo.sp_add_subscription_event \r\n    @subscription_id = @SubscriptionID,\r\n    @event_type = 'shared_schedule',\r\n    @schedule_id = 'B5CA5C5C-8DFA-4DCA-94EE-12345CCB9F56'<\/code><\/pre>\n<p>[\/vc_column_text][\/vc_column][\/vc_row][vc_row el_class=&#8221;blog-detail-section&#8221;][vc_column][vc_column_text]<\/p>\n<h2>4. SQL Server\u76e3\u63a7\u548c\u6545\u969c\u6392\u9664<\/h2>\n<p><strong><a href=\"https:\/\/www.simcentric.com\/tc\/hong-kong-dedicated-server\/how-to-manage-and-improve-sql-server-efficiency\/\" target=\"_blank\" rel=\"noopener\">\u6709\u6548\u7684\u76e3\u63a7\u548c\u6545\u969c\u6392\u9664<\/a><\/strong>\u5c0d\u65bc\u7dad\u8b77\u6700\u4f73SQL Server\u6027\u80fd\u81f3\u95dc\u91cd\u8981\u3002<\/p>\n<h3>4.1 \u4f7f\u7528\u52d5\u614b\u7ba1\u7406\u8996\u5716(DMV)<\/h3>\n<p>DMV\u63d0\u4f9b\u4e86\u6709\u95dc\u4f3a\u670d\u5668\u6027\u80fd\u7684\u5bf6\u8cb4\u6d1e\u5bdf\u3002\u4ee5\u4e0b\u662f\u7528\u65bc\u8b58\u5225\u6d88\u8017\u6700\u591a\u8cc7\u6e90\u7684\u67e5\u8a62\u7684\u67e5\u8a62:<\/p>\n<pre><code>SELECT TOP 10\r\n    qs.execution_count,\r\n    qs.total_logical_reads, qs.last_logical_reads,\r\n    qs.total_logical_writes, qs.last_logical_writes,\r\n    qs.total_worker_time, qs.last_worker_time,\r\n    qs.total_elapsed_time\/1000000 total_elapsed_time_in_S,\r\n    qs.last_elapsed_time\/1000000 last_elapsed_time_in_S,\r\n    qs.last_execution_time,\r\n    qp.query_plan\r\nFROM \r\n    sys.dm_exec_query_stats qs\r\nCROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) st\r\nCROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qp\r\nORDER BY \r\n    qs.total_logical_reads DESC<\/code><\/pre>\n<h3>4.2 \u7528\u65bc\u9ad8\u7d1a\u76e3\u63a7\u7684\u64f4\u5c55\u4e8b\u4ef6<\/h3>\n<p>\u4f7f\u7528\u64f4\u5c55\u4e8b\u4ef6\u9032\u884c\u8a73\u7d30\u7684\u6027\u80fd\u76e3\u63a7\u3002\u4ee5\u4e0b\u662f\u5275\u5efa\u64f4\u5c55\u4e8b\u4ef6\u6703\u8a71\u4ee5\u6355\u7372\u67e5\u8a62\u8d85\u6642\u7684\u8173\u672c:<\/p>\n<pre><code>CREATE EVENT SESSION [CaptureQueryTimeouts] ON SERVER \r\nADD EVENT sqlserver.rpc_completed(\r\n    ACTION(sqlserver.client_app_name,sqlserver.client_hostname,sqlserver.database_name,sqlserver.session_id,sqlserver.sql_text)\r\n    WHERE ([result]=(2))),\r\nADD EVENT sqlserver.sql_batch_completed(\r\n    ACTION(sqlserver.client_app_name,sqlserver.client_hostname,sqlserver.database_name,sqlserver.session_id,sqlserver.sql_text)\r\n    WHERE ([result]=(2)))\r\nADD TARGET package0.event_file(SET filename=N'C:\\Logs\\QueryTimeouts.xel')\r\nWITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,MAX_DISPATCH_LATENCY=30 SECONDS,MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=NONE,TRACK_CAUSALITY=OFF,STARTUP_STATE=OFF)\r\nGO\r\n\r\nALTER EVENT SESSION [CaptureQueryTimeouts] ON SERVER STATE = START;<\/code><\/pre>\n<h3>4.3 \u4f7f\u7528\u67e5\u8a62\u5b58\u5132\u9032\u884c\u6027\u80fd\u8abf\u512a<\/h3>\n<p>\u67e5\u8a62\u5b58\u5132\u63d0\u4f9b\u4e86\u96a8\u6642\u9593\u8b8a\u5316\u7684\u67e5\u8a62\u6027\u80fd\u6d1e\u5bdf\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u555f\u7528\u548c\u4f7f\u7528\u67e5\u8a62\u5b58\u5132:<\/p>\n<pre><code>ALTER DATABASE YourDatabase\r\nSET QUERY_STORE = ON \r\n(\r\n    OPERATION_MODE = READ_WRITE,\r\n    CLEANUP_POLICY = ( STALE_QUERY_THRESHOLD_DAYS = 30 ),\r\n    DATA_FLUSH_INTERVAL_SECONDS = 3000,\r\n    INTERVAL_LENGTH_MINUTES = 15,\r\n    MAX_STORAGE_SIZE_MB = 1000,\r\n    QUERY_CAPTURE_MODE = ALL,\r\n    SIZE_BASED_CLEANUP_MODE = AUTO,\r\n    MAX_PLANS_PER_QUERY = 200\r\n)\r\n\r\n-- Query to find regressed queries\r\nSELECT \r\n    q.query_id, \r\n    qt.query_text_id, \r\n    qt.query_sql_text, \r\n    rs.runtime_stats_id,\r\n    rsi.start_time,\r\n    rsi.end_time,\r\n    rs.avg_duration\r\nFROM sys.query_store_query_text AS qt\r\nJOIN sys.query_store_query AS q\r\n    ON qt.query_text_id = q.query_text_id\r\nJOIN sys.query_store_plan AS p\r\n    ON q.query_id = p.query_id\r\nJOIN sys.query_store_runtime_stats AS rs\r\n    ON p.plan_id = rs.plan_id\r\nJOIN sys.query_store_runtime_stats_interval AS rsi\r\n    ON rsi.runtime_stats_interval_id = rs.runtime_stats_interval_id\r\nWHERE rs.avg_duration &gt; 1000  -- 1 second\r\nORDER BY rs.avg_duration DESC;<\/code><\/pre>\n<p>[\/vc_column_text][\/vc_column][\/vc_row][vc_row el_class=&#8221;blog-detail-section&#8221;][vc_column][vc_column_text]<\/p>\n<h2>5. \u7d50\u8ad6\u548c\u672a\u4f86\u5c55\u671b<\/h2>\n<p>\u6b63\u5982\u6211\u5011\u6240\u63a2\u8a0e\u7684,SQL Server\u70ba\u512a\u5316\u548c\u61c9\u7528\u7a0b\u5f0f\u958b\u767c\u63d0\u4f9b\u4e86\u8c50\u5bcc\u7684\u9ad8\u7d1a\u529f\u80fd\u3002\u5f9e\u78ba\u4fdd\u9ad8\u53ef\u7528\u6027\u548c\u7121\u7e2b\u6578\u64da\u9077\u79fb\u5230\u5275\u5efa\u52d5\u614b\u5831\u8868\u548c\u5be6\u65bd\u5f37\u5927\u7684\u76e3\u63a7\u89e3\u6c7a\u65b9\u6848,\u9019\u4e9b\u6280\u8853\u4f7f\u6578\u64da\u5eab\u7ba1\u7406\u54e1\u548c\u958b\u767c\u4eba\u54e1\u80fd\u5920\u69cb\u5efa\u53ef\u64f4\u5c55\u3001\u9ad8\u6548\u548c\u53ef\u9760\u7684\u6578\u64da\u5eab\u7cfb\u7d71\u3002<\/p>\n<p>\u5c55\u671b\u672a\u4f86,SQL Server\u7684\u524d\u666f\u8207\u96f2\u6280\u8853\u548c\u4eba\u5de5\u667a\u6167\u5bc6\u5207\u76f8\u95dc\u3002\u6211\u5011\u53ef\u4ee5\u671f\u5f85\u770b\u5230\u66f4\u591a\u8207Azure\u670d\u52d9\u7684\u96c6\u6210\u3001\u6578\u64da\u5eab\u5f15\u64ce\u5167\u589e\u5f37\u7684\u6a5f\u5668\u5b78\u7fd2\u529f\u80fd,\u4ee5\u53ca\u7528\u65bc\u7ba1\u7406\u6df7\u5408\u96f2\u74b0\u5883\u7684\u6539\u9032\u5de5\u5177\u3002\u96a8\u8457\u6578\u64da\u91cf\u7684\u6301\u7e8c\u589e\u9577,\u5217\u5b58\u5132\u7d22\u5f15\u548c\u8a18\u61b6\u9ad4\u5167OLTP\u7b49\u6280\u8853\u5c07\u8b8a\u5f97\u66f4\u52a0\u95dc\u9375,\u4ee5\u4fdd\u6301\u5927\u898f\u6a21\u6027\u80fd\u3002<\/p>\n<p>\u70ba\u4e86\u5728\u9019\u500b\u5feb\u901f\u767c\u5c55\u7684\u9818\u57df\u4fdd\u6301\u9818\u5148\u5730\u4f4d,\u6578\u64da\u5eab\u5c08\u696d\u4eba\u54e1\u61c9\u8a72\u95dc\u6ce8:<\/p>\n<ul>\n<li>\u52a0\u6df1\u5c0d\u96f2\u67b6\u69cb\u548c\u6df7\u5408\u89e3\u6c7a\u65b9\u6848\u7684\u7406\u89e3<\/li>\n<li>\u63a2\u7d22\u6578\u64da\u5eab\u7cfb\u7d71\u5167\u7684\u6a5f\u5668\u5b78\u7fd2\u548cAI\u96c6\u6210<\/li>\n<li>\u638c\u63e1\u65e5\u76ca\u8907\u96dc\u7684\u76e3\u7ba1\u74b0\u5883\u4e2d\u7684\u6578\u64da\u5b89\u5168\u548c\u5408\u898f\u6027<\/li>\n<li>\u63a1\u7528DevOps\u5be6\u8e10\u9032\u884c\u6578\u64da\u5eab\u958b\u767c\u548c\u7ba1\u7406<\/li>\n<\/ul>\n<p>\u901a\u904e\u5229\u7528\u9019\u4e9b\u5148\u9032\u7684SQL Server\u529f\u80fd\u4e26\u95dc\u6ce8\u65b0\u8208\u8da8\u52e2,\u7d44\u7e54\u53ef\u4ee5\u78ba\u4fdd\u5176\u6578\u64da\u5eab\u7cfb\u7d71\u4fdd\u6301\u5f37\u5927\u3001\u9ad8\u6548,\u4e26\u6e96\u5099\u597d\u8fce\u63a5\u672a\u4f86\u6578\u64da\u9a45\u52d5\u4e16\u754c\u7684\u6311\u6230\u3002<\/p>\n<p>[\/vc_column_text][\/vc_column][\/vc_row]<\/p>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>[vc_row el_class=&#8221;blog-detail-section&#8221;][vc_ [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"https:\/\/www.simcentric.com\/tc\/hong-kong-dedicated-server-tc\/what-techniques-boost-sql-server-efficiency\/\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":2,"featured_media":14903,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[61],"tags":[3148,3149,3150,2525,1630],"class_list":["post-14936","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hong-kong-dedicated-server-tc","tag-data-migration-tc","tag-ssrs-tc","tag-database-monitoring-tc","tag-sql-server-tc","tag-troubleshooting-tc"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>\u54ea\u4e9b\u6280\u8853\u53ef\u4ee5\u63d0\u9ad8SQL Server\u7684\u6548\u7387?<\/title>\n<meta name=\"description\" content=\"\u63a2\u7d22SQL Server\u512a\u5316\u6280\u8853\u548c\u61c9\u7528\uff0c\u5305\u62ec\u9ad8\u53ef\u7528\u6027\u89e3\u6c7a\u65b9\u6848\u3001\u6578\u64da\u9077\u79fb\u3001SSRS\u3001\u76e3\u63a7\u548c\u6545\u969c\u6392\u9664\u3002\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/posts\/14936\" \/>\n<meta property=\"og:locale\" content=\"zh_TW\" \/>\n<meta property=\"og:type\" content=\"company\" \/>\n<meta property=\"og:title\" content=\"\u54ea\u4e9b\u6280\u8853\u53ef\u4ee5\u63d0\u9ad8SQL Server\u7684\u6548\u7387?\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/posts\/14936\" \/>\n<meta property=\"og:site_name\" content=\"\u65b0\u5929\u57df\u4e92\u806f\" \/>\n<meta property=\"article:published_time\" content=\"2024-08-22T04:09:21+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-08-22T04:14:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.simcentric.com\/wp-content\/uploads\/2024\/08\/sim-blog-2024-08-22-D-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"620\" \/>\n\t<meta property=\"og:image:height\" content=\"340\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u54ea\u4e9b\u6280\u8853\u53ef\u4ee5\u63d0\u9ad8SQL Server\u7684\u6548\u7387?","description":"\u63a2\u7d22SQL Server\u512a\u5316\u6280\u8853\u548c\u61c9\u7528\uff0c\u5305\u62ec\u9ad8\u53ef\u7528\u6027\u89e3\u6c7a\u65b9\u6848\u3001\u6578\u64da\u9077\u79fb\u3001SSRS\u3001\u76e3\u63a7\u548c\u6545\u969c\u6392\u9664\u3002","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/posts\/14936","og_locale":"zh_TW","og_type":"company","og_title":"\u54ea\u4e9b\u6280\u8853\u53ef\u4ee5\u63d0\u9ad8SQL Server\u7684\u6548\u7387?","og_url":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/posts\/14936","og_site_name":"\u65b0\u5929\u57df\u4e92\u806f","article_published_time":"2024-08-22T04:09:21+00:00","article_modified_time":"2024-08-22T04:14:52+00:00","og_image":[{"width":620,"height":340,"url":"https:\/\/www.simcentric.com\/wp-content\/uploads\/2024\/08\/sim-blog-2024-08-22-D-1.jpg","type":"image\/jpeg"}],"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.simcentric.com\/tc\/hong-kong-dedicated-server-tc\/what-techniques-boost-sql-server-efficiency\/#article","isPartOf":{"@id":"https:\/\/www.simcentric.com\/tc\/hong-kong-dedicated-server-tc\/what-techniques-boost-sql-server-efficiency\/"},"author":{"name":"Debbie Ng","@id":"https:\/\/simcentric.com\/tc\/#\/schema\/person\/0bfc8768eb7caacbfab4a0855d805626"},"headline":"\u54ea\u4e9b\u6280\u8853\u53ef\u4ee5\u63d0\u9ad8SQL Server\u7684\u6548\u7387?","datePublished":"2024-08-22T04:09:21+00:00","dateModified":"2024-08-22T04:14:52+00:00","mainEntityOfPage":{"@id":"https:\/\/www.simcentric.com\/tc\/hong-kong-dedicated-server-tc\/what-techniques-boost-sql-server-efficiency\/"},"wordCount":176,"publisher":{"@id":"https:\/\/simcentric.com\/tc\/#organization"},"image":{"@id":"https:\/\/www.simcentric.com\/tc\/hong-kong-dedicated-server-tc\/what-techniques-boost-sql-server-efficiency\/#primaryimage"},"thumbnailUrl":"https:\/\/www.simcentric.com\/wp-content\/uploads\/2024\/08\/sim-blog-2024-08-22-D-1.jpg","keywords":["\u6578\u64da\u9077\u79fb","SSRS","\u8cc7\u6599\u5eab\u76e3\u63a7","SQL\u4f3a\u670d\u5668","\u6545\u969c\u6392\u9664"],"articleSection":["\u9999\u6e2f\u4f3a\u670d\u5668"],"inLanguage":"zh-HK"},{"@type":"WebPage","@id":"https:\/\/www.simcentric.com\/tc\/hong-kong-dedicated-server-tc\/what-techniques-boost-sql-server-efficiency\/","url":"https:\/\/www.simcentric.com\/tc\/hong-kong-dedicated-server-tc\/what-techniques-boost-sql-server-efficiency\/","name":"\u54ea\u4e9b\u6280\u8853\u53ef\u4ee5\u63d0\u9ad8SQL Server\u7684\u6548\u7387?","isPartOf":{"@id":"https:\/\/simcentric.com\/tc\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.simcentric.com\/tc\/hong-kong-dedicated-server-tc\/what-techniques-boost-sql-server-efficiency\/#primaryimage"},"image":{"@id":"https:\/\/www.simcentric.com\/tc\/hong-kong-dedicated-server-tc\/what-techniques-boost-sql-server-efficiency\/#primaryimage"},"thumbnailUrl":"https:\/\/www.simcentric.com\/wp-content\/uploads\/2024\/08\/sim-blog-2024-08-22-D-1.jpg","datePublished":"2024-08-22T04:09:21+00:00","dateModified":"2024-08-22T04:14:52+00:00","description":"\u63a2\u7d22SQL Server\u512a\u5316\u6280\u8853\u548c\u61c9\u7528\uff0c\u5305\u62ec\u9ad8\u53ef\u7528\u6027\u89e3\u6c7a\u65b9\u6848\u3001\u6578\u64da\u9077\u79fb\u3001SSRS\u3001\u76e3\u63a7\u548c\u6545\u969c\u6392\u9664\u3002","breadcrumb":{"@id":"https:\/\/www.simcentric.com\/tc\/hong-kong-dedicated-server-tc\/what-techniques-boost-sql-server-efficiency\/#breadcrumb"},"inLanguage":"zh-HK","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.simcentric.com\/tc\/hong-kong-dedicated-server-tc\/what-techniques-boost-sql-server-efficiency\/"]}]},{"@type":"ImageObject","inLanguage":"zh-HK","@id":"https:\/\/www.simcentric.com\/tc\/hong-kong-dedicated-server-tc\/what-techniques-boost-sql-server-efficiency\/#primaryimage","url":"https:\/\/www.simcentric.com\/wp-content\/uploads\/2024\/08\/sim-blog-2024-08-22-D-1.jpg","contentUrl":"https:\/\/www.simcentric.com\/wp-content\/uploads\/2024\/08\/sim-blog-2024-08-22-D-1.jpg","width":620,"height":340,"caption":"SQL Server\u512a\u5316\u5716\u793a"},{"@type":"BreadcrumbList","@id":"https:\/\/www.simcentric.com\/tc\/hong-kong-dedicated-server-tc\/what-techniques-boost-sql-server-efficiency\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.simcentric.com\/tc\/"},{"@type":"ListItem","position":2,"name":"\u54ea\u4e9b\u6280\u8853\u53ef\u4ee5\u63d0\u9ad8SQL Server\u7684\u6548\u7387?"}]},{"@type":"WebSite","@id":"https:\/\/simcentric.com\/tc\/#website","url":"https:\/\/simcentric.com\/tc\/","name":"Simcentric Solutions","description":"","publisher":{"@id":"https:\/\/simcentric.com\/tc\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/simcentric.com\/tc\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-HK"},{"@type":"Organization","@id":"https:\/\/simcentric.com\/tc\/#organization","name":"Simcentric Solutions","url":"https:\/\/simcentric.com\/tc\/","logo":{"@type":"ImageObject","inLanguage":"zh-HK","@id":"https:\/\/simcentric.com\/tc\/#\/schema\/logo\/image\/","url":"https:\/\/www.simcentric.com\/wp-content\/uploads\/2023\/06\/sim-logo-2023.png","contentUrl":"https:\/\/www.simcentric.com\/wp-content\/uploads\/2023\/06\/sim-logo-2023.png","width":800,"height":222,"caption":"Simcentric Solutions"},"image":{"@id":"https:\/\/simcentric.com\/tc\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/simcentric.com\/tc\/#\/schema\/person\/0bfc8768eb7caacbfab4a0855d805626","name":"Debbie Ng","image":{"@type":"ImageObject","inLanguage":"zh-HK","@id":"https:\/\/secure.gravatar.com\/avatar\/9f3420f60d27329ed6e921ddaae5206353d0a7414d1abb6f1f0b32b4fd849965?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/9f3420f60d27329ed6e921ddaae5206353d0a7414d1abb6f1f0b32b4fd849965?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9f3420f60d27329ed6e921ddaae5206353d0a7414d1abb6f1f0b32b4fd849965?s=96&d=mm&r=g","caption":"Debbie Ng"}}]}},"_links":{"self":[{"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/posts\/14936","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/comments?post=14936"}],"version-history":[{"count":1,"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/posts\/14936\/revisions"}],"predecessor-version":[{"id":14939,"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/posts\/14936\/revisions\/14939"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/media\/14903"}],"wp:attachment":[{"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/media?parent=14936"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/categories?post=14936"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/tags?post=14936"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}