Beginning Microsoft SQL Server 2008 ... - S3 Tech Training
Beginning Microsoft SQL Server 2008 ... - S3 Tech Training Beginning Microsoft SQL Server 2008 ... - S3 Tech Training
Appendix A: System Functions In addition, we have the OVER operator, which, while largely working as a ranking tool, can be applied to other forms of T-SQL functions (most notably aggregates). While I only discuss it as part of the ranking functions, you may see it referenced several other places in this appendix. Legacy System Functions (a.k.a. Global Variables) @@CONNECTIONS Returns the number of connections attempted since the last time your SQL Server was started. This one is the total of all connection attempts made since the last time your SQL Server was started. The key thing to remember here is that we are talking about attempts, not actual connections, and that we are talking about connections as opposed to users. Every attempt made to create a connection increments this counter regardless of whether that connection was successful or not. The only catch with this is that the connection attempt has to have made it as far as the server. If the connection failed because of NetLib differences or some other network issue, then your SQL Server wouldn’t even know that it needed to increase the count — it only counts if the server saw the connection attempt. Whether the attempt succeeded or failed does not matter. It’s also important to understand that we’re talking about connections instead of login attempts. Depending on your application, you may create several connections to your server, but you’ll probably only ask the user for information once. Indeed, even Query Analyzer does this. When you click for a new window, it automatically creates another connection based on the same login information. This, like a number of other system functions, is often better served by a system stored procedure, sp_monitor. This procedure, in one command, produces the information from the number of connections, CPU busy, through to the total number of writes by SQL Server. So, if basic information is what you’re after, then sp_monitor may be better — if you need discrete data that you can manipulate, then @@CONNECTIONS provides a nice, neat, scalar piece of data. @@CPU_BUSY 588 Returns the time in milliseconds that the CPU has been actively doing work since SQL Server was last started. This number is based on the resolution of the system timer — which can vary — and can therefore vary in accuracy. This is another of the “since the server started” kind of functions. This means that you can’t always count on the number going up as your application runs. It’s possible, based on this number, to figure out a CPU percentage that your SQL Server is taking up. Realistically though, I’d rather tap right into the Performance Monitor for that if I had some dire need for it. The bottom line is that this is one of those really cool things from a “gee, isn’t it swell to know that” point of view, but doesn’t have all that many practical uses in most applications.
@@IDLE Returns the time in milliseconds (based on the resolution of the system timer) that SQL Server has been idle since it was last started. You can think of this one as being something of the inverse of @@CPU_BUSY. Essentially, it tells you how much time your SQL Server has spent doing nothing. If anyone finds a programmatic use for this one, send me an e-mail — I’d love to hear about it (I can’t think of one). @@IO_BUSY Returns the time in milliseconds (based on the resolution of the system timer) that SQL Server has spent doing input and output operations since it was last started. This value is reset every time SQL Server is started. This one doesn’t really have any rocket science to it, and it is another one of those that I find falls into the “no real programmatic use” category. @@PACK_RECEIVED and @@PACK_SENT Respectively return the number of input packets read/written from/to the network by SQL Server since it was last started. Primarily, these are network troubleshooting tools. @@PACKET_ERRORS Returns the number of network packet errors that have occurred on connections to your SQL Server since the last time the SQL Server was started. Primarily a network troubleshooting tool. @@TIMETICKS Returns the number of microseconds per tick. This varies by machines and is another of those that falls under the category of “no real programmatic use.” @@TOTAL_ERRORS Apendix A: System Functions Returns the number of disk read/write errors encountered by the SQL Server since it was last started. Don’t confuse this with runtime errors or as having any relation to @@ERROR. This is about problems with physical I/O. This one is another of those of the “no real programmatic use” variety. The primary use here would be more along the lines of system diagnostic scripts. Generally speaking, I would use Performance Monitor for this instead. 589
- Page 576 and 577: Chapter 17: Reporting for Duty, Sir
- Page 578 and 579: Chapter 17: Reporting for Duty, Sir
- Page 580 and 581: Chapter 17: Reporting for Duty, Sir
- Page 582 and 583: Chapter 18: Getting Integrated with
- Page 584 and 585: Chapter 18: Getting Integrated with
- Page 586 and 587: Chapter 18: Getting Integrated with
- Page 588 and 589: Chapter 18: Getting Integrated with
- Page 590 and 591: Chapter 18: Getting Integrated with
- Page 592 and 593: Chapter 18: Getting Integrated with
- Page 594 and 595: Chapter 18: Getting Integrated with
- Page 596 and 597: Chapter 18: Getting Integrated with
- Page 598 and 599: Chapter 18: Getting Integrated with
- Page 601 and 602: 19 Playing Administrator And so, he
- Page 603 and 604: ❑ Write the information to the ev
- Page 605 and 606: Creating Jobs and Tasks Using Manag
- Page 607 and 608: Let’s go ahead and move on to the
- Page 609 and 610: Figure 19-8 Figure 19-9 Chapter 19:
- Page 611 and 612: Figure 19-11 Figure 19-12 Chapter 1
- Page 613 and 614: Backup and Reco very No database-dr
- Page 615 and 616: ❑ Differential: This might be ref
- Page 617 and 618: ❑ Simple: Under this model, the t
- Page 619 and 620: The older DBCC commands are still s
- Page 621 and 622: many rows inserted over time and th
- Page 623: Chapter 19: Playing Administrator T
- Page 628 and 629: Appendix A: System Functions @@TOTA
- Page 630 and 631: Appendix A: System Functions CHECKS
- Page 632 and 633: Appendix A: System Functions SUM Th
- Page 634 and 635: Appendix A: System Functions The de
- Page 636 and 637: Appendix A: System Functions @@REMS
- Page 638 and 639: Appendix A: System Functions Cert_I
- Page 640 and 641: Appendix A: System Functions Encryp
- Page 642 and 643: Appendix A: System Functions @@FETC
- Page 644 and 645: Appendix A: System Functions CURREN
- Page 646 and 647: Appendix A: System Functions SYSDAT
- Page 648 and 649: Appendix A: System Functions GetRoo
- Page 650 and 651: Appendix A: System Functions The ex
- Page 652 and 653: Appendix A: System Functions RAND T
- Page 654 and 655: Appendix A: System Functions ❑ IN
- Page 656 and 657: Appendix A: System Functions ❑ Is
- Page 658 and 659: Appendix A: System Functions FILEGR
- Page 660 and 661: Appendix A: System Functions INDEX_
- Page 662 and 663: IsCheckCnst IsConstraint IsDefault
- Page 664 and 665: Appendix A: System Functions OBJECT
- Page 666 and 667: Appendix A: System Functions TYPEPR
- Page 668 and 669: Appendix A: System Functions The qu
- Page 670 and 671: Appendix A: System Functions The SU
- Page 672 and 673: Appendix A: System Functions ASCII
- Page 674 and 675: Appendix A: System Functions The ch
Appendix A: System Functions<br />
In addition, we have the OVER operator, which, while largely working as a ranking tool, can be applied<br />
to other forms of T-<strong>SQL</strong> functions (most notably aggregates). While I only discuss it as part of the ranking<br />
functions, you may see it referenced several other places in this appendix.<br />
Legacy System Functions<br />
(a.k.a. Global Variables)<br />
@@CONNECTIONS<br />
Returns the number of connections attempted since the last time your <strong>SQL</strong> <strong>Server</strong> was started.<br />
This one is the total of all connection attempts made since the last time your <strong>SQL</strong> <strong>Server</strong> was started. The<br />
key thing to remember here is that we are talking about attempts, not actual connections, and that we<br />
are talking about connections as opposed to users.<br />
Every attempt made to create a connection increments this counter regardless of whether that connection<br />
was successful or not. The only catch with this is that the connection attempt has to have made it as far<br />
as the server. If the connection failed because of NetLib differences or some other network issue, then<br />
your <strong>SQL</strong> <strong>Server</strong> wouldn’t even know that it needed to increase the count — it only counts if the server<br />
saw the connection attempt. Whether the attempt succeeded or failed does not matter.<br />
It’s also important to understand that we’re talking about connections instead of login attempts. Depending<br />
on your application, you may create several connections to your server, but you’ll probably only ask<br />
the user for information once. Indeed, even Query Analyzer does this. When you click for a new window,<br />
it automatically creates another connection based on the same login information.<br />
This, like a number of other system functions, is often better served by a system stored procedure,<br />
sp_monitor. This procedure, in one command, produces the information from the number of connections,<br />
CPU busy, through to the total number of writes by <strong>SQL</strong> <strong>Server</strong>. So, if basic information is what<br />
you’re after, then sp_monitor may be better — if you need discrete data that you can manipulate,<br />
then @@CONNECTIONS provides a nice, neat, scalar piece of data.<br />
@@CPU_BUSY<br />
588<br />
Returns the time in milliseconds that the CPU has been actively doing work since <strong>SQL</strong> <strong>Server</strong> was last<br />
started. This number is based on the resolution of the system timer — which can vary — and can therefore<br />
vary in accuracy.<br />
This is another of the “since the server started” kind of functions. This means that you can’t always count<br />
on the number going up as your application runs. It’s possible, based on this number, to figure out a CPU<br />
percentage that your <strong>SQL</strong> <strong>Server</strong> is taking up. Realistically though, I’d rather tap right into the Performance<br />
Monitor for that if I had some dire need for it. The bottom line is that this is one of those really cool<br />
things from a “gee, isn’t it swell to know that” point of view, but doesn’t have all that many practical<br />
uses in most applications.