dbcc

SQL SERVER DBCC 命令集整理

好久不见. 提交于 2020-04-24 23:29:12
1. DBCC CHECKALLOC 检查指定数据库的磁盘空间分配结构的一致性。 DBCC CHECKALLOC [ (database_name | database_id | 0 [ , NOINDEX | , { REPAIR_ALLOW_DATA_LOSS | REPAIR_FAST | REPAIR_REBUILD } ] ) [ WITH { [ ALL_ERRORMSGS ] [ , NO_INFOMSGS ] [ , TABLOCK ] [ , ESTIMATEONLY ] } ] ] 2. DBCC CHECKCATALOG 检查指定数据库内的目录一致性。数据库必须联机。 DBCC CHECKCATALOG [ ( database_name | database_id | 0 ) ] [ WITH NO_INFOMSGS ] 3. DBCC CHECKCONSTRAINTS 检查当前数据库中指定表上的指定约束或所有约束的完整性。 DBCC CHECKCONSTRAINTS [ ( table_name | table_id | constraint_name | constraint_id ) ] [ WITH [ { ALL_CONSTRAINTS | ALL_ERRORMSGS } ] [ , ] [ NO_INFOMSGS ] ] 4. DBCC

Get last command in SQL Server without DBCC INPUTBUFFER

我的梦境 提交于 2020-02-21 16:43:13
问题 Is there a way to get the last executed SQL Server command without the use of DBCC INPUTBUFFER ? For example, is there a System View or Catalog that contains this information? Thanks. 回答1: You can pass your SPID (SQL Process ID) to the following: DECLARE @sql_handle VARBINARY(128); SELECT @sql_handle = sql_handle FROM sys.sysprocesses WHERE spid = @@SPID; --you can pass a different SPID here SELECT [text] FROM sys.dm_exec_sql_text(@sql_handle); 回答2: Yes, from SQL Server 2014 SP4 and newer ,

DBCC CheckDb-any ways to detect errors vb.net?

风格不统一 提交于 2019-12-13 02:58:09
问题 I am using the below code to check if my database has any issues/requires troubleshooting: Dim cmd As New SqlCommand("DBCC CHECKDB (offpoDb) WITH TABLERESULTS", con) Dim reader As SqlDataReader = cmd.ExecuteReader executing.Content = "Checking datatabse for errors" executing.Margin = New Thickness(243, 111, 0, 0) While reader.Read strBuilder.AppendLine(CStr(reader("MessageText"))) End While reader.Close() MessageBox.Show(strBuilder.ToString) Now, the DBCC CHECKDB command might result in

Can parameterized queries be fully captured using DBCC INPUTBUFFER?

谁说胖子不能爱 提交于 2019-12-11 04:56:05
问题 In SQL Server 2008, I am using triggers to capture all changes made to a specific table in my database. My goal is to capture the entire change. That is, to capture what data is being inserted, not just that data is being inserted. In the trigger I am using the EventInfo column of the result set returned by DBCC INPUTBUFFER to get the currently executing SQL statement as well as the Parameters column to get a count of the parameters used. This works in most cases, but when an external

Is DBCC command a stored procedure or a function?

谁说我不能喝 提交于 2019-12-11 03:38:56
问题 What should be the DBCC commands be called ? DBCC procedure or DBCC function? It is confusing because DBCC PAGE could be executed without prefixing a EXEC statement much like stored procedures. But EXEC DBCC PAGE(1,1,1,3) throws an error Syntax error - Msg 156 Incorrect syntax near the keyword 'DBCC' And it isn't a function because function calling must be made in SELECT , but SELECT DBCC PAGE(1,1,1,3) shows the same error. 回答1: As far as I know DBCC stands for Data-Base-Console-Command.

SQL identity (1,1) starting at 0

戏子无情 提交于 2019-12-08 19:38:23
问题 I have a SQL table with an identity set: CREATE TABLE MyTable( MyTableID int IDENTITY(1,1) NOT NULL, RecordName nvarchar(100) NULL) Something has happened to this table, resulting in odd behaviour. I need to find out what. When an insert occurs: INSERT MyTable(RecordName) VALUES('Test Bug') SELECT SCOPE_IDENTITY() -- returns 0 SELECT * FROM MyTable -- displays: 0, 'Test Bug' This is a problem because code above this insert expects the first ID to be 1 - I can't figure out how with IDENTITY(1

Reduce SQL Server table fragmentation without adding/dropping a clustered index?

时间秒杀一切 提交于 2019-12-03 17:41:51
问题 I have a large database (90GB data, 70GB indexes) that's been slowly growing for the past year, and the growth/changes has caused a large amount of internal fragmentation not only of the indexes, but of the tables themselves. It's easy to resolve the (large number of) very fragmented indexes - a REORGANIZE or REBUILD will take care of that, depending on how fragmented they are - but the only advice I can find on cleaning up actual table fragmentation is to add a clustered index to the table.

Reduce SQL Server table fragmentation without adding/dropping a clustered index?

半城伤御伤魂 提交于 2019-12-03 05:55:26
I have a large database (90GB data, 70GB indexes) that's been slowly growing for the past year, and the growth/changes has caused a large amount of internal fragmentation not only of the indexes, but of the tables themselves. It's easy to resolve the (large number of) very fragmented indexes - a REORGANIZE or REBUILD will take care of that, depending on how fragmented they are - but the only advice I can find on cleaning up actual table fragmentation is to add a clustered index to the table. I'd immediately drop it afterwards, as I don't want a clustered index on the table going forward, but

Currently running query inside a stored procedure

和自甴很熟 提交于 2019-11-29 12:29:13
问题 I have a stored procedure that is currently running, and seems to hang/lock on a specific query. How can i see which query? Preferably without modifying the proc. Using DBCC Inputbuffer (65) gives me Language Event 0 EXEC mySP; 回答1: There is an excellent stored procedure to get extended information on currently running queries. It's available to download from: http://whoisactive.com 回答2: SELECT SUBSTRING(st.text, ( r.statement_start_offset / 2 ) + 1, ( ( CASE WHEN r.statement_end_offset <= 0

DBCC SHRINKFILE on log file not reducing size even after BACKUP LOG TO DISK

自作多情 提交于 2019-11-28 13:57:44
问题 I've got a database, [My DB], that has the following info: SQL Server 2008 MDF size: 30 GB LDF size: 67 GB I wanted to shrink the log file as much as possible and so I started my quest to figure out how to do this. Caveat: I am not a DBA (or even approaching a DBA) and have been progressing by feel through this quest. First, I just went into SSMS, DB properties, Files, and edited the Initial Size (MB) value to 10. That reduced the log file to 62 GB (not exactly the 10 MB that I entered). So,