---------------
-- 1 - Debugger
---------------
-- Set breakpoints on all of the Print clauses

USE Pubs

DECLARE @Datetime datetime
DECLARE @Count int
DECLARE @Bogus varchar(10)

SET @Datetime = GETDATE()

SELECT	@Count = COUNT(a.au_lname) 
FROM dbo.Authors a
INNER JOIN dbo.TitleAuthor ta
ON a.au_id = ta.au_id
INNER JOIN dbo.Titles t
ON ta.title_id = t.title_id
WHERE a.state = 'CA'
AND t.pubdate < @Datetime

-- SELECT @Count

IF @Count = 1
BEGIN
	PRINT 'Condition 1'
END

IF @Count > 1
BEGIN
	PRINT 'Condition 2'
END

IF @Count < 1 
BEGIN
	PRINT 'Condition 3'
END
GO


---------------------------------------
-- 2 - Copy columns with the result set
---------------------------------------
USE AdventureWorks
GO

SELECT * 
FROM Person.Contact
WHERE DATEDIFF(DAY,ModifiedDate, GETDATE())>1
GO

-- Copy the results from section 1
-- Paste to Excel
-- Show how all of the results are correct in Excel
-- May need to change how Excel displays the data


--------------------------------
-- 3 - Copy and paste from Excel
--------------------------------
USE AdventureWorks
GO
CREATE TABLE [dbo].[MyTable]( 
      [MyID] [int] NOT NULL, 
      [MyDesc] [varchar](100) NOT NULL) 
GO

-- Navigate to the table
-- Edit Top 200 rows
-- Copy and paste from Excel from 1.3-Demo.xlsx
 
SELECT * 
FROM [dbo].[MyTable]
GO

DROP TABLE [dbo].[MyTable]
GO


----------------------------------
-- 4 - Prevent table creation code
----------------------------------
Ever noticed sometimes when you change a table in SSMS or EM that it takes forever to complete?
Do you know why?
SQL Server is creating a temp table
Moving all of the data to the temp table
Drops the original table
Builds the indexes on the new tables
On large tables, this is a time consuming process

So how can you control that on the client side?

Let's walk through an example...

AdventureWorks
Person.Contact
Add CellPhone column
Tools | Options | Designers | Table and Database Designers
Prevent saving changes that require table re-creation


-----------------------
-- 5 - Activity Monitor
-----------------------
Tool bar - Activity Monitor
Panes
	Overview
	Processes
	Resource Waits
	Data File I/O
	Recent Expensive Queries
Refresh rate
	Overview 
	Right click and select rate
Processes
	Details
	KILL
	Profiler to capture data
