2

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.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
LonelyRogue
  • 376
  • 1
  • 2
  • 10
  • 1
    [DBCC](https://learn.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-transact-sql?view=sql-server-2017) is a statement, not a function or stored procedure. You can't call stored procedures without `exec` either, [unless they are the first statement in a batch](https://learn.microsoft.com/en-us/sql/relational-databases/stored-procedures/execute-a-stored-procedure?view=sql-server-2017) – Panagiotis Kanavos Aug 09 '19 at 09:31
  • In fact, the error message itself explains this - `Incorrect syntax near the keyword 'DBCC'`. To the server, DBCC is a keyword, just like EXEC or SELECT – Panagiotis Kanavos Aug 09 '19 at 09:33
  • 1
    In addition to `DBCC PAGE` being a statement, many `DBCC` commands have syntax conventions that deviate from the norms of T-SQL (insofar as it can be said to have norms) and have custom parsing, so you can do things like leave out parameters in what looks like a function call (which T-SQL functions do not support). On top of *that*, `DBCC PAGE` in particular is of course not officially documented. In SQL Server 2019 most of its uses will be served by the new `sys.dm_db_page_info` function, which is a proper function that can participate in queries. – Jeroen Mostert Aug 09 '19 at 09:36
  • @PanagiotisKanavos Then DBCC is another object category much like Table objects, View Objects, SProc objects etc.. Thank you! – LonelyRogue Aug 09 '19 at 09:58
  • @LonelyRogue no,it's not. It's not an object at all. It's a *keyword* like CREATE, SELECT, INSERT, EXEC, PRINT. That's what the error itself says – Panagiotis Kanavos Aug 09 '19 at 09:58
  • @JeroenMostert thanks for adding about sys.dm_db_page_info – LonelyRogue Aug 09 '19 at 09:59

1 Answers1

-1

As far as I know DBCC stands for Data-Base-Console-Command. Therefore, DBCC by its self is neither a procedure nor a function. It is simply a console that you recall.