翻譯|使用教程|編輯:吳園園|2020-03-18 11:27:11.167|閱讀 334 次
概述:本文討論了使用SQL Complete工具刪除丟失的事務。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
dbForge SQL Complete是一款用于Microsoft SQL Server Management Studio和Microsoft Visual Studio的功能強大的插件。SQL代碼格式化程序(免費版和高級付費版)能夠提供可以取代原生的Microsoft T-SQL Intellisense特性的T-SQL代碼自動實現和格式化功能。
更多內容請點擊查看上一篇
高級格式化選項
鑒于此,您需要更深入的自定義選項,請導航至“ SQL Complete”的“選項”窗口。從主菜單可以很容易地做到這一點。
接下來,在邊欄中,導航至格式。
格式選項卡有兩個子選項卡。在常規子選項卡上,您可以:
在“ 配置文件”子選項卡上,您將找到格式配置文件的列表。在此選項卡上,您還可以編輯現有配置文件,創建新配置文件,激活所需的配置文件或打開包含格式化配置文件的文件夾。
如果要編輯配置文件或檢查配置文件規則,則需要突出顯示所需的配置文件,然后單擊“ 編輯配置文件”按鈕。或者,您可以雙擊所需的配置文件。
如何啟用或禁用dbForge SQL Complete
可能會遇到由于SSMS太慢而需要禁用該工具的情況。只需單擊幾下即可完成。只需在該工具的主菜單中單擊“禁用代碼完成”即可。
相應地,如果要啟用該工具,請單擊“ 啟用代碼完成”選項。
回到這一點,我們創建了表srv.SessionTran來記錄丟失的事務的終止會話。
如何根據刪除操作創建表以存檔丟失的交易
現在,以類似的方式,我們將創建一個表,以根據刪除操作來存檔從第一個表中選擇的事務。
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [srv].[KillSession]( [ID] [int] IDENTITY(1,1) NOT NULL, [session_id] [smallint] NOT NULL, [transaction_id] [bigint] NOT NULL, [login_time] [datetime] NOT NULL, [host_name] [nvarchar](128) NULL, [program_name] [nvarchar](128) NULL, [host_process_id] [int] NULL, [client_version] [int] NULL, [client_interface_name] [nvarchar](32) NULL, [security_id] [varbinary](85) NOT NULL, [login_name] [nvarchar](128) NOT NULL, [nt_domain] [nvarchar](128) NULL, [nt_user_name] [nvarchar](128) NULL, [status] [nvarchar](30) NOT NULL, [context_info] [varbinary](128) NULL, [cpu_time] [int] NOT NULL, [memory_usage] [int] NOT NULL, [total_scheduled_time] [int] NOT NULL, [total_elapsed_time] [int] NOT NULL, [endpoint_id] [int] NOT NULL, [last_request_start_time] [datetime] NOT NULL, [last_request_end_time] [datetime] NULL, [reads] [bigint] NOT NULL, [writes] [bigint] NOT NULL, [logical_reads] [bigint] NOT NULL, [is_user_process] [bit] NOT NULL, [text_size] [int] NOT NULL, [language] [nvarchar](128) NULL, [date_format] [nvarchar](3) NULL, [date_first] [smallint] NOT NULL, [quoted_identifier] [bit] NOT NULL, [arithabort] [bit] NOT NULL, [ansi_null_dflt_on] [bit] NOT NULL, [ansi_defaults] [bit] NOT NULL, [ansi_warnings] [bit] NOT NULL, [ansi_padding] [bit] NOT NULL, [ansi_nulls] [bit] NOT NULL, [concat_null_yields_null] [bit] NOT NULL, [transaction_isolation_level] [smallint] NOT NULL, [lock_timeout] [int] NOT NULL, [deadlock_priority] [int] NOT NULL, [row_count] [bigint] NOT NULL, [prev_error] [int] NOT NULL, [original_security_id] [varbinary](85) NOT NULL, [original_login_name] [nvarchar](128) NOT NULL, [last_successful_logon] [datetime] NULL, [last_unsuccessful_logon] [datetime] NULL, [unsuccessful_logons] [bigint] NULL, [group_id] [int] NOT NULL, [database_id] [smallint] NOT NULL, [authenticating_database_id] [int] NULL, [open_transaction_count] [int] NOT NULL, [most_recent_session_id] [int] NULL, [connect_time] [datetime] NULL, [net_transport] [nvarchar](40) NULL, [protocol_type] [nvarchar](40) NULL, [protocol_version] [int] NULL, [encrypt_option] [nvarchar](40) NULL, [auth_scheme] [nvarchar](40) NULL, [node_affinity] [smallint] NULL, [num_reads] [int] NULL, [num_writes] [int] NULL, [last_read] [datetime] NULL, [last_write] [datetime] NULL, [net_packet_size] [int] NULL, [client_net_address] [nvarchar](48) NULL, [client_tcp_port] [int] NULL, [local_net_address] [nvarchar](48) NULL, [local_tcp_port] [int] NULL, [connection_id] [uniqueidentifier] NULL, [parent_connection_id] [uniqueidentifier] NULL, [most_recent_sql_handle] [varbinary](64) NULL, [LastTSQL] [nvarchar](max) NULL, [transaction_begin_time] [datetime] NOT NULL, [CountTranNotRequest] [tinyint] NOT NULL, [CountSessionNotRequest] [tinyint] NOT NULL, [InsertUTCDate] [datetime] NOT NULL, CONSTRAINT [PK_KillSession] PRIMARY KEY CLUSTERED ( [ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO ALTER TABLE [srv].[KillSession] ADD CONSTRAINT [DF_KillSession_InsertUTCDate] DEFAULT (getutcdate()) FOR [InsertUTCDate] GO
在此腳本中:
sys.dm_exec_sessions和sys.dm_exec_connections引用系統視圖
InsertUTCDate 標識創建記錄時的UTC日期和時間。
結論
在本文中,我們介紹了刪除SQL Server中丟失的事務的通用算法,并探討了如何在SQL Complete的幫助下實現該算法。除此之外,還展示了該工具的明顯優勢。IntelliSense風格的代碼完成,高度可定制和可共享的代碼格式,高效的代碼重構以及許多其他有用的功能旨在照顧您的代碼,讓您專注于代碼的實際工作方式。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自: