翻譯|使用教程|編輯:吳園園|2020-03-18 11:27:11.167|閱讀 334 次
概述:本文討論了使用SQL Complete工具刪除丟失的事務(wù)。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷(xiāo)售中 >>
相關(guān)鏈接:
dbForge SQL Complete是一款用于Microsoft SQL Server Management Studio和Microsoft Visual Studio的功能強(qiáng)大的插件。SQL代碼格式化程序(免費(fèi)版和高級(jí)付費(fèi)版)能夠提供可以取代原生的Microsoft T-SQL Intellisense特性的T-SQL代碼自動(dòng)實(shí)現(xiàn)和格式化功能。
點(diǎn)擊下載dbForge SQL Complete最新試用版
更多內(nèi)容請(qǐng)點(diǎn)擊查看上一篇
高級(jí)格式化選項(xiàng)
鑒于此,您需要更深入的自定義選項(xiàng),請(qǐng)導(dǎo)航至“ SQL Complete”的“選項(xiàng)”窗口。從主菜單可以很容易地做到這一點(diǎn)。
接下來(lái),在邊欄中,導(dǎo)航至格式。
格式選項(xiàng)卡有兩個(gè)子選項(xiàng)卡。在常規(guī)子選項(xiàng)卡上,您可以:
在“ 配置文件”子選項(xiàng)卡上,您將找到格式配置文件的列表。在此選項(xiàng)卡上,您還可以編輯現(xiàn)有配置文件,創(chuàng)建新配置文件,激活所需的配置文件或打開(kāi)包含格式化配置文件的文件夾。
如果要編輯配置文件或檢查配置文件規(guī)則,則需要突出顯示所需的配置文件,然后單擊“ 編輯配置文件”按鈕。或者,您可以雙擊所需的配置文件。
如何啟用或禁用dbForge SQL Complete
可能會(huì)遇到由于SSMS太慢而需要禁用該工具的情況。只需單擊幾下即可完成。只需在該工具的主菜單中單擊“禁用代碼完成”即可。
相應(yīng)地,如果要啟用該工具,請(qǐng)單擊“ 啟用代碼完成”選項(xiàng)。
回到這一點(diǎn),我們創(chuàng)建了表srv.SessionTran來(lái)記錄丟失的事務(wù)的終止會(huì)話。
如何根據(jù)刪除操作創(chuàng)建表以存檔丟失的交易
現(xiàn)在,以類(lèi)似的方式,我們將創(chuàng)建一個(gè)表,以根據(jù)刪除操作來(lái)存檔從第一個(gè)表中選擇的事務(wù)。
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引用系統(tǒng)視圖
InsertUTCDate 標(biāo)識(shí)創(chuàng)建記錄時(shí)的UTC日期和時(shí)間。
結(jié)論
在本文中,我們介紹了刪除SQL Server中丟失的事務(wù)的通用算法,并探討了如何在SQL Complete的幫助下實(shí)現(xiàn)該算法。除此之外,還展示了該工具的明顯優(yōu)勢(shì)。IntelliSense風(fēng)格的代碼完成,高度可定制和可共享的代碼格式,高效的代碼重構(gòu)以及許多其他有用的功能旨在照顧您的代碼,讓您專(zhuān)注于代碼的實(shí)際工作方式。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自: