concept number in category sql

This is an excerpt from Manning's book SQL Server MVP Deep Dives Vol. 2.
For this query, the optimizer will “sniff” the predicate literal value USA and consult the statistics on the [Country] column. It will decide, based on the estimated number of US customers, whether it’s best to scan the [Customers] table (the most efficient approach when the number of US customers is high) or to use a noncovering, nonclustered index with a key lookup (the most efficient approach when this number is low).
When I was 19 years old, I took a big step onto what United States Marines know as the yellow footprints. The yellow footprints are symbolic of the steps a recruit needs to take to become a Marine. The first and longest-lasting impression is how this marks the starting point of your Marine Corps career. To the drill instructors looking at recruits standing on the yellow footprints, it symbolizes the beginning of molding young men and women into Marines. During this molding process, recruits are exposed to a number of experiences that are designed to teach them all the skills needed to reach the end goal. Some of these experiences are going to hurt; some of these experiences may appear redundant, such as learning to brush your teeth. But all of these experiences are specifically put in place because someone understands that each of these young people will need to know these skills in order to become a successful Marine.
Listing 3. Capturing the number of page reads per second with T-SQL
-- Collect first sample DECLARE @old_cntr_value INT; DECLARE @first_sample_date DATETIME; SELECT @old_cntr_value = cntr_value, @first_sample_date = getdate() FROM sys.dm_os_performance_counters WHERE counter_name = 'Page reads/sec'; -- Time frame to wait before collecting second sample WAITFOR DELAY '00:00:10'; -- Collect second sample and calculate per-second counter SELECT (cntr_value - @old_cntr_value) / DATEDIFF(ss,@first_sample_date, GETDATE()) as PageReadPerSec FROM sys.dm_os_performance_counters WHERE counter_name = 'Page reads/sec' AND object_name = CASE WHEN @@SERVICENAME = 'MSSQLSERVER' THEN 'SQLServer:Buffer Manager' ELSE 'MSSQL$' + rtrim(@@SERVICENAME) + ':Buffer Manager' END;

This is an excerpt from Manning's book SQL Server DMVs in Action: Better Queries with Dynamic Management Views.
A special mention should be made about the humble GO command. The GO command will execute the batch of SQL statements that occurs after the last GO statements. If GO is followed by a number, then it will execute that number of times. This is useful in many circumstances; for example, after an INSERT statement if you put GO 50, the insert will occur 50 times.
This GO number pattern can be extended to provide a simple concurrency/blocking/deadlock test harness. If you enter a similar batch of SQL statements into two or more distinct windows within SQL Server Management Studio (SSMS), and the statements are followed with a GO 5000 and the SQL in all windows run at the same time, you can discover the effect of repeatedly running the SQL at the same time.
The test harness described here allows you to record performance details relating to your queries, for example, total duration, number of reads, and number of writes. Its purpose is to obtain these performance metrics first when the unchanged SQL query is run and then again when you change the query to incorporate a potential improvement. For example, you might change the algorithm the SQL query uses or add an index that you think might be useful. Finally, you compare the two outputs and determine whether the change is an improvement.
The script given in this section will enable you to test the changes in your queries within a generic test framework. The script will output, for each SQL query run within a given batch or stored procedure, the total duration of the query, the time it spent using the CPU, the time it spent waiting (or being blocked), the number of reads, the number of writes, the number of times each line of SQL within the query was executed, the text of the individual SQL query, the text of the parent SQL query, and the database the query ran on.
You can discover the number of physical CPUs by running the following SQL snippet:

This is an excerpt from Manning's book SQL Server MVP Deep Dives.
One example of using a function is limiting the cardinality of a value in a database (or the count of the times a value can appear). Using a unique constraint, you can easily limit the cardinality to 1, but if you want to allow a number different than 1, there isn’t an easy way to do this declaratively. So we can use a function and a check constraint. Take the following table:
Auxiliary table of numbers
As you can see after passing a value of 1 for the number argument, the date was incremented by a month. If we pass in a negative number, we’ll get a date that’s a month earlier than we passed in, as the following code demonstrates:
SELECT DATEADD(mm,-1,'20090501')
(Result set)
2009-04-01 00:00:00.000Now it’s time to use our numbers table to create some dates. The query in listing 2 will add one month multiplied by the number in the numbers table to today’s date and return the next 100 months, beginning with today’s date.