├── 9781484219638.jpg
├── LICENSE.txt
├── README.md
├── SQL Server Internals 2nd Edition
├── .Net
│ ├── 13.Chapter 13 (Temporary Objects and TempDB)
│ │ ├── SaveRecordSet.sln
│ │ └── SaveRecordSetApp
│ │ │ ├── MainForm.Designer.cs
│ │ │ ├── MainForm.cs
│ │ │ ├── MainForm.resx
│ │ │ ├── Program.cs
│ │ │ ├── Properties
│ │ │ ├── AssemblyInfo.cs
│ │ │ ├── Resources.Designer.cs
│ │ │ ├── Resources.resx
│ │ │ ├── Settings.Designer.cs
│ │ │ └── Settings.settings
│ │ │ ├── SaveRecordSetApp.csproj
│ │ │ ├── app.config
│ │ │ ├── bin-.Net 3.5
│ │ │ └── Debug
│ │ │ │ ├── SaveRecordSetApp.exe
│ │ │ │ ├── SaveRecordSetApp.exe.config
│ │ │ │ ├── SaveRecordSetApp.pdb
│ │ │ │ ├── SaveRecordSetApp.vshost.exe
│ │ │ │ ├── SaveRecordSetApp.vshost.exe.config
│ │ │ │ └── SaveRecordSetApp.vshost.exe.manifest
│ │ │ ├── bin-.Net 4.5
│ │ │ └── Debug
│ │ │ │ ├── SaveRecordSetApp.exe
│ │ │ │ ├── SaveRecordSetApp.exe.config
│ │ │ │ ├── SaveRecordSetApp.pdb
│ │ │ │ ├── SaveRecordSetApp.vshost.exe
│ │ │ │ ├── SaveRecordSetApp.vshost.exe.config
│ │ │ │ └── SaveRecordSetApp.vshost.exe.manifest
│ │ │ └── obj
│ │ │ └── x86
│ │ │ └── Debug
│ │ │ ├── DesignTimeResolveAssemblyReferences.cache
│ │ │ ├── DesignTimeResolveAssemblyReferencesInput.cache
│ │ │ ├── SaveRecordSetApp.Form1.resources
│ │ │ ├── SaveRecordSetApp.MainForm.resources
│ │ │ ├── SaveRecordSetApp.Properties.Resources.resources
│ │ │ ├── SaveRecordSetApp.csproj.FileListAbsolute.txt
│ │ │ ├── SaveRecordSetApp.csproj.GenerateResource.Cache
│ │ │ ├── SaveRecordSetApp.csprojResolveAssemblyReference.cache
│ │ │ ├── SaveRecordSetApp.exe
│ │ │ ├── SaveRecordSetApp.pdb
│ │ │ ├── TempPE
│ │ │ └── Properties.Resources.Designer.cs.dll
│ │ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ │ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ │ │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
│ ├── 14.Chapters 14-15 (CLR)
│ │ ├── SQL Server 2005
│ │ │ ├── CLRTest.sln
│ │ │ └── CLRTest
│ │ │ │ ├── CLRProcedures.cs
│ │ │ │ ├── CLRTest.dbmdl
│ │ │ │ ├── CLRTest.sqlproj
│ │ │ │ ├── CLRTest.sqlproj.user
│ │ │ │ ├── Concat.cs
│ │ │ │ ├── ScalarUDF.cs
│ │ │ │ ├── USPostalAddress.cs
│ │ │ │ ├── bin
│ │ │ │ └── Debug
│ │ │ │ │ ├── CLRTest.dacpac
│ │ │ │ │ ├── CLRTest.dll
│ │ │ │ │ ├── CLRTest.pdb
│ │ │ │ │ └── CLRTest_Create.sql
│ │ │ │ └── obj
│ │ │ │ └── Debug
│ │ │ │ ├── CLRTEST.generated.sql
│ │ │ │ ├── CLRTest.dll
│ │ │ │ ├── CLRTest.pdb
│ │ │ │ ├── CLRTest.sqlproj.FileListAbsolute.txt
│ │ │ │ └── Model.xml
│ │ ├── SQL Server 2008-2008R2
│ │ │ ├── CLRTest.sln
│ │ │ └── CLRTest
│ │ │ │ ├── CLRProcedures.cs
│ │ │ │ ├── CLRTest.dbmdl
│ │ │ │ ├── CLRTest.sqlproj
│ │ │ │ ├── CLRTest.sqlproj.user
│ │ │ │ ├── Concat.cs
│ │ │ │ ├── ScalarUDF.cs
│ │ │ │ ├── USPostalAddress.cs
│ │ │ │ ├── bin
│ │ │ │ └── Debug
│ │ │ │ │ ├── CLRTest.dacpac
│ │ │ │ │ ├── CLRTest.dll
│ │ │ │ │ ├── CLRTest.pdb
│ │ │ │ │ └── CLRTest_Create.sql
│ │ │ │ └── obj
│ │ │ │ └── Debug
│ │ │ │ ├── CLRTEST.generated.sql
│ │ │ │ ├── CLRTest.dll
│ │ │ │ ├── CLRTest.pdb
│ │ │ │ ├── CLRTest.sqlproj.FileListAbsolute.txt
│ │ │ │ └── Model.xml
│ │ └── SQL Server 2012-2016
│ │ │ ├── CLRTest.sln
│ │ │ └── CLRTest
│ │ │ ├── CLRProcedures.cs
│ │ │ ├── CLRTest.dbmdl
│ │ │ ├── CLRTest.sqlproj
│ │ │ ├── CLRTest.sqlproj.user
│ │ │ ├── Concat.cs
│ │ │ ├── ScalarUDF.cs
│ │ │ ├── USPostalAddress.cs
│ │ │ ├── bin
│ │ │ └── Debug
│ │ │ │ ├── CLRTest.dacpac
│ │ │ │ ├── CLRTest.dll
│ │ │ │ ├── CLRTest.pdb
│ │ │ │ └── CLRTest_Create.sql
│ │ │ └── obj
│ │ │ └── Debug
│ │ │ ├── CLRTEST.generated.sql
│ │ │ ├── CLRTest.dll
│ │ │ ├── CLRTest.pdb
│ │ │ ├── CLRTest.sqlproj.FileListAbsolute.txt
│ │ │ └── Model.xml
│ └── 99.Chapter 99 (System Design Considerations)
│ │ ├── EF6
│ │ ├── App.config
│ │ ├── EF6.csproj
│ │ ├── EF6Tests.cs
│ │ ├── EFDbContext.cs
│ │ ├── Mapping
│ │ │ ├── CustomerMap.cs
│ │ │ └── OrderMap.cs
│ │ ├── Properties
│ │ │ └── AssemblyInfo.cs
│ │ └── packages.config
│ │ ├── Model
│ │ ├── Customer.cs
│ │ ├── Model.csproj
│ │ ├── Order.cs
│ │ ├── OrderItem.cs
│ │ └── Properties
│ │ │ └── AssemblyInfo.cs
│ │ ├── ORMTests.sln
│ │ └── ORMTests
│ │ ├── App.config
│ │ ├── ORMTests.csproj
│ │ ├── Program.cs
│ │ ├── Properties
│ │ └── AssemblyInfo.cs
│ │ └── packages.config
└── SQL
│ ├── 00.Init
│ ├── 00.Init (SQL Server 2014-2016).ssmssqlproj
│ ├── 00.Init.ssmssqlproj
│ ├── 01.DB Creation.sql
│ └── 02.Create In-Memory OLTP DB.sql
│ ├── 01.Chapter 01 (Data Storage Internals)
│ ├── 01.Chapter 01 (Data Storage Internals).ssmssqlproj
│ ├── 01.Check Instant File Initialization.sql
│ ├── 02.Data Row Format.sql
│ ├── 03.Select and IO.sql
│ ├── 04.Row size and Performance.sql
│ └── 05.Alteration.sql
│ ├── 02.Chapter 02 (Tables and Indexes)
│ ├── 01.Heaps and PFS.sql
│ ├── 02.Chapter 02 (Tables and Indexes) (SQL Server 2016).ssmssqlproj
│ ├── 02.Chapter 02 (Tables and Indexes).ssmssqlproj
│ ├── 02.Forwarding Pointers.sql
│ ├── 03.SARGability and Data Types.sql
│ ├── 04.Max NCI Key Size (SQL Server 2016).sql
│ ├── 04.Max NCI Key Size.sql
│ └── 05.Nonclustered Index Usage.sql
│ ├── 03.Chapter 03 (Statistics)
│ ├── 01.Exploring Statistics.sql
│ ├── 02.Column-level Statistics.sql
│ ├── 03.Chapter 03 (Statistics) (SQL Server 2014).ssmssqlproj
│ ├── 03.Chapter 03 (Statistics) (SQL Server 2016).ssmssqlproj
│ ├── 03.Chapter 03 (Statistics).ssmssqlproj
│ ├── 03.Statistics and Exec Plans.sql
│ ├── 04.Statistics and Memory Grants.sql
│ ├── 05.SQL Server 2014-2016 Cardinality Estimators.sql
│ └── 05.SQL Server 2016 Cardinality Estimator.sql
│ ├── 04.Chapter 04 (Special Features)
│ ├── 01.Included Columns.sql
│ ├── 02.Filtered Indexes.sql
│ ├── 03.Filtered Statistics.sql
│ ├── 04.Calculated Columns.sql
│ ├── 04.Chapter 04 (Special Features) (SQL Server 2005).ssmssqlproj
│ ├── 04.Chapter 04 (Special Features).ssmssqlproj
│ ├── 05.Row Compression.sql
│ ├── 07.Sparse Columns.sql
│ └── 99.Estimating Page Compression.sql
│ ├── 05.Chapter 05 (SQL Server 2016 Features)
│ ├── 01.Temporal Tables.sql
│ ├── 02.Stretch Databases.sql
│ ├── 03.RLS.sql
│ ├── 04.Dynamic Data Masking.sql
│ └── 05.Chapter 05 (SQL Server 2016 Features).ssmssqlproj
│ ├── 06.Chapter 06 (Index Fragmentation)
│ ├── 01.Page Splits.sql
│ ├── 02.Row Size Increase on Update.sql
│ └── 06.Chapter 06 (Index Fragmentation).ssmssqlproj
│ ├── 07.Chapter 07 (Designing and Tuning The Indexes)
│ ├── 01.Nonunique CI.sql
│ ├── 02.Uniqueidentifiers.sql
│ ├── 03.Checksum.sql
│ ├── 04.Index Intersection.sql
│ ├── 05.Sys.dm_db_index_usage_stats.sql
│ ├── 06.Redundant Indexes.sql
│ ├── 07.Chapter 07 (Designing and Tuning The Indexes).ssmssqlproj
│ └── 07.Suboptimal Queries.sql
│ ├── 08.Chapter 08 (Constraints)
│ ├── 01.FK.sql
│ ├── 02.Check Constraints Overhead.sql
│ └── 08.Chapter 08 (Constraints).ssmssqlproj
│ ├── 09.Chapter 09 (Triggers)
│ ├── 01.Merge.sql
│ ├── 02.Triggers and Fragmentation.sql
│ ├── 03.DDL Triggers.sql
│ ├── 04.Context_Info.sql
│ ├── 05.Session Context.sql
│ ├── 09.Chapter 09 (Triggers) (SQL Server 2005).ssmssqlproj
│ ├── 09.Chapter 09 (Triggers) (SQL Server 2016).ssmssqlproj
│ └── 09.Chapter 09 (Triggers).ssmssqlproj
│ ├── 10.Chapter 10 (Views)
│ ├── 01.Join Elimination (Single-column join).sql
│ ├── 02.Join Elimination (Multi-column join).sql
│ ├── 03.Indexed Views.sql
│ ├── 04.Supporting Uniqueness with Indexed Views.sql
│ ├── 05.CHECK Option.sql
│ └── 10.Chapter 10 (Views).ssmssqlproj
│ ├── 11.Chapter 11 (Functions)
│ ├── 01.Code Reuse.sql
│ ├── 02.Scalar UDF.sql
│ ├── 03.Multi-statement UDF.sql
│ ├── 03.Optimizing with CTE.sql
│ ├── 11.Chapter 11 (Functions) (SQL Server 2005).ssmssqlproj
│ └── 11.Chapter 11 (Functions).ssmssqlproj
│ ├── 12.Chapter 12 (XML and JSON)
│ ├── 01.Primary XML Index.sql
│ ├── 02.XML Storage Space.sql
│ ├── 03.Working with XML.sql
│ ├── 04.FOR XML.sql
│ ├── 05.Working With JSON.sql
│ ├── 12.Chapter 12 (XML and JSON) (SQL Server 2016).ssmssqlproj
│ └── 12.Chapter 12 (XML and JSON).ssmssqlproj
│ ├── 13.Chapter 13 (Temporary Objects and TempDb)
│ ├── 01.Temp Tables - Scope and Lifetime.sql
│ ├── 02.Temp Tables and Cardinality Estimations.sql
│ ├── 03.Temp Table Caching.sql
│ ├── 04.Table Variables.sql
│ ├── 05.Table Variables and Transactions.sql
│ ├── 06.TVP Scope.sql
│ ├── 07.TVP - Batch Insert (SQL Server 2005).sql
│ ├── 07.TVP - Batch Insert (SQL Server 2016).sql
│ ├── 07.TVP - Batch Insert.sql
│ ├── 13.Chapter 13 (Temporary Objects and TempDb) (SQL Server 2005).ssmssqlproj
│ ├── 13.Chapter 13 (Temporary Objects and TempDb) (SQL Server 2016).ssmssqlproj
│ └── 13.Chapter 13 (Temporary Objects and TempDb).ssmssqlproj
│ ├── 14.Chapter 14 (CLR)
│ ├── 01.Object Creation (SQL Server 2005).sql
│ ├── 01.Object Creation (SQL Server 2008).sql
│ ├── 01.Object Creation (SQL Server 2012-2016).sql
│ ├── 02.Scalar UDF.sql
│ ├── 03.Complex Calculations.sql
│ ├── 04.Data Access.sql
│ ├── 05.Cursor vs. Reader.sql
│ ├── 06.Aggregate (SQL Server 2005).sql
│ ├── 06.Aggregate.sql
│ ├── 07.Non-Yelding CLR.sql
│ ├── 14.Chapter 14 (CLR) (SQL Server 2005).ssmssqlproj
│ ├── 14.Chapter 14 (CLR) (SQL Server 2008-2008R2).ssmssqlproj
│ └── 14.Chapter 14 (CLR).ssmssqlproj
│ ├── 15.Chapter 15 (CLR Types)
│ ├── 01.UDT.sql
│ ├── 02.Spatital.sql
│ ├── 03.Bounding Box.sql
│ ├── 04.HierarchyId.sql
│ ├── 15.Chapter 15 (CLR Types) (SQL Server 2005).ssmssqlproj
│ └── 15.Chapter 15 (CLR Types).ssmssqlproj
│ ├── 16.Chapter 16 (Data Partitioning)
│ ├── 01.Creating Partitioned Table.sql
│ ├── 02.Switching Partition.sql
│ ├── 03.Creating Partitioned Views.sql
│ ├── 04.Partitioned Tables and Views Together.sql
│ ├── 05.Moving Nonpartitioned Tables.sql
│ ├── 06.Moving Partition.sql
│ ├── 07.Moving Data Between Disk Arrays.sql
│ ├── 08.Sliding Window.sql
│ ├── 09.Optimizing with $Partition function.sql
│ └── 16.Chapter 16 (Data Partitioning).ssmssqlproj
│ ├── 17.Chapter 17 (Lock Types)
│ ├── 01.(X) and (IX) locks.sql
│ ├── 02.(U) locks.sql
│ ├── 03.1.(S) Locks.sql
│ ├── 03.2.(S) Locks.sql
│ ├── 04.1.(X) Lock Behavior.sql
│ ├── 04.2.(X) Lock Behavior.sql
│ ├── 05.(S) Locks Behavior.sql
│ └── 17.Chapter 17 (Lock Types).ssmssqlproj
│ ├── 18.Chapter 18 (Troubleshooting Blocking Issues)
│ ├── 01.1.Creating Blocking.sql
│ ├── 01.2.Creating Blocking.sql
│ ├── 02.DMVs.sql
│ ├── 03.Set Blocked Process Threshold.sql
│ ├── 04.Obtaining SQL and Plan by sql_handle.sql
│ ├── 05.Obtaining SQL and Plan from sys_dm_exec_requests.sql
│ ├── 06.Capturing Blocking Info with Event Notifications.sql
│ ├── 18.Chapter 18 (Troubleshooting Blocking Issues) (SQL Server 2005).ssmssqlproj
│ └── 18.Chapter 18 (Troubleshooting Blocking Issues).ssmssqlproj
│ ├── 19.Chapter 19 (Deadlocks)
│ ├── 01.1.Non-optimized Queries Deadlock.sql
│ ├── 01.2.Non-optimized Queries Deadlock.sql
│ ├── 01.3.Non-optimized Queries Deadlock.sql
│ ├── 02.1.Key Lookup Deadlock.sql
│ ├── 02.2.Key Lookup Deadlock.sql
│ ├── 03.1.Multiple Updates.sql
│ ├── 03.2.Multiple Updates.sql
│ └── 19.Chapter 19 (Deadlocks).ssmssqlproj
│ ├── 20.Chapter 20 (Lock Escalations)
│ ├── 01.1.Lock Escalation and Concurrency.sql
│ ├── 01.2 Lock Escalation and Concurrency.sql
│ ├── 02.Multiple Statements.sql
│ └── 20.Chapter 20 (Lock Escalations).ssmssqlproj
│ ├── 21.Chapter 21 (Optimistic Isolation Levels)
│ ├── 01.1.RCSI.sql
│ ├── 01.2.RCSI.sql
│ ├── 02.1.Snapshot.sql
│ ├── 02.2.Snapshot.sql
│ ├── 03.1.Error 3960.sql
│ ├── 03.2.Error 3960.sql
│ ├── 04.1.Optimistic vs Pessimistic Locking.sql
│ ├── 04.2.Optimistic vs Pessimistic Locking.sql
│ └── 21.Chapter 21 (Optimistic Isolation Levels).ssmssqlproj
│ ├── 22.Chapter 22 (Application Locks)
│ ├── 01.Table Creation.sql
│ ├── 02.1.Application Locks.sql
│ ├── 02.2.Application Locks.sql
│ ├── 03.1.Workaround With Locking Hints.sql
│ ├── 03.2.Workaround With Locking Hints.sql
│ └── 22.Chapter 22 (Application Locks).ssmssqlproj
│ ├── 23.Chapter 23 (Schema Locks)
│ ├── 01.1.Schema Locks.sql
│ ├── 01.2.Schema Locks.sql
│ ├── 01.3.Schema Locks.sql
│ ├── 02.1.Lock Compatibility.sql
│ ├── 02.2.Lock Compatibility.sql
│ ├── 02.3.Lock Compatibility.sql
│ ├── 03.1.Low Priority Locks.sql
│ ├── 03.2.Low Priority Locks.sql
│ ├── 03.3.Low Priority Locks.sql
│ ├── 23.Chapter 23 (Schema Locks) (SQL Server 2014-2016).ssmssqlproj
│ └── 23.Chapter 23 (Schema Locks).ssmssqlproj
│ ├── 25.Chapter 25 (Query Optimization and Execution)
│ ├── 01.Removing Contradictions.sql
│ ├── 02.Variable-length Cols and Memory Grants.sql
│ ├── 03.Spools.sql
│ ├── 04.Halloween Protection.sql
│ ├── 05.Parallelism.sql
│ └── 25.Chapter 25 (Query Optimization and Execution).ssmssqlproj
│ ├── 26.Chapter 26 (Plan Caching)
│ ├── 01.Parameter Sniffing.sql
│ ├── 02.Plan Reuse.sql
│ ├── 03.Ad-Hoc queries.sql
│ ├── 04.Forced Parameterization and Filtered Indexes.sql
│ ├── 05.Plan Guides.sql
│ ├── 06.Examining Plan Cache.sql
│ ├── 26.Chapter 26 (Plan Caching) (SQL Server 2005).ssmssqlproj
│ └── 26.Chapter 26 (Plan Caching).ssmssqlproj
│ ├── 27.Chapter 27 (Extended Events)
│ ├── 01.Extended Events Objects.sql
│ ├── 02.Monitoring TempDB Spills.sql
│ ├── 03.Ring_Buffer Target.sql
│ ├── 04.Event_File Target.sql
│ ├── 05.Event_Counter Target.sql
│ ├── 06.Histogram Target.sql
│ ├── 07.Pair_Matching Target.sql
│ ├── 08.Expensive Queries.sql
│ ├── 09.Monitoring Page Splits.sql
│ ├── 27.Chapter 27 (Extended Events) (SQL Server 2008).ssmssqlproj
│ └── 27.Chapter 27 (Extended Events).ssmssqlproj
│ ├── 28.Chapter 28 (System Troubleshooting)
│ ├── 01.Wait Statistics.sql
│ ├── 02.Sys-dm_io_virtual_file_stats.sql
│ ├── 03.Execution Statistics.sql
│ ├── 04.Buffer Pool Usage.sql
│ ├── 05.Memory-Related Issues.sql
│ ├── 06.Enable Remote DAC.sql
│ ├── 07.Detecting Run-Away Queries.sql
│ ├── 08.Latch Stats.sql
│ ├── 09.Locking.sql
│ └── 28.Chapter 28 (System Troubleshooting).ssmssqlproj
│ ├── 29.Chapter 29 (Query Store)
│ ├── 01.Configure Query Store.sql
│ ├── 02.1.Emulating Parameter Sniffing.sql
│ ├── 02.2.Emulating Parameter Sniffing.sql
│ ├── 03.Working with Query Store.sql
│ ├── 04.Query Store Maintenance.sql
│ ├── 05.Disable Query Store (Cleanup).sql
│ └── 29.Chapter 29 (Query Store).ssmssqlproj
│ ├── 30.Chapter 30 (Transaction Log Internals)
│ ├── 01.Troubleshooting Log Growth.sql
│ └── 30.Chapter 30 (Transaction Log Internals).ssmssqlproj
│ ├── 31.Chapter 31 (Backup and Restore)
│ ├── 01.Create Test DB.sql
│ ├── 02.Backing Up and Restoring DB.sql
│ ├── 03.Point In Time Restore.sql
│ ├── 04.Restore With Standby.sql
│ ├── 05.Restoring After Disaster.sql
│ ├── 06.Partial DB Availability.sql
│ ├── 07.Piecemeal Restore.sql
│ ├── 08.Partial Backup.sql
│ └── 31.Chapter 31 (Backup and Restore).ssmssqlproj
│ ├── 33.Chapter 33 (Column-Based Storage and Batch Mode Execution)
│ ├── 01.Batch Mode Execution.sql
│ ├── 02.Columnstore Index Metadata.sql
│ ├── 03.String Columns in Predicates.sql
│ └── 33.Chapter 33 (Column-Based Storage and Batch Mode Execution).ssmssqlproj
│ ├── 34.Chapter 34 (Columnstore Indexes)
│ ├── 01.Switching Partition.sql
│ ├── 02.Delta Store and Delete Bitmap.sql
│ ├── 03.Delta Store Data Compression.sql
│ ├── 04.Delete Bitmap Compression.sql
│ ├── 05.Clustered Columnstore with Nonclusterd B-Tree.sql
│ ├── 06.Updateable Nonclustered Columnstore Indexes.sql
│ ├── 07.DMVs (2014).sql
│ ├── 07.DMVs (2016).sql
│ ├── 34.Chapter 34 (Columnstore Indexes) (SQL Server 2012).ssmssqlproj
│ ├── 34.Chapter 34 (Columnstore Indexes) (SQL Server 2014).ssmssqlproj
│ └── 34.Chapter 34 (Columnstore Indexes) (SQL Server 2016).ssmssqlproj
│ ├── 35.Chapter 35 (In-Memory OLTP Internals)
│ ├── 01.Composite Hash Index.sql
│ ├── 02.Memory Consumers (SQL Server 2014).sql
│ ├── 02.Memory Consumers.sql
│ ├── 03.Memory Consumers and Off-Row Storage.sql
│ ├── 04.Columnstore Indexes.sql
│ ├── 05.Memory Usage.sql
│ ├── 35.Chapter 35 (In-Memory OLTP Internals) (SQL Server 2014).ssmssqlproj
│ └── 35.Chapter 35 (In-Memory OLTP Internals) (SQL Server 2016).ssmssqlproj
│ ├── 36.Chapter 36 (Transaction Processing in In-Memory OLTP)
│ ├── 01.Test Table Creation.sql
│ ├── 02.1.Concurrency in Repeatable Read.sql
│ ├── 02.2.Concurrency in Repeatable Read.sql
│ ├── 03.1.Concurrency in Serializable.sql
│ ├── 03.2.Concurrency in Serializable.sql
│ ├── 04.1.Concurrency in Snapshot.sql
│ ├── 04.2.Concurrency in Snapshot.sql
│ ├── 05.1.PK Violation.sql
│ ├── 05.2.PK Violation.sql
│ ├── 06.1.Write-write Conflict.sql
│ ├── 06.2.Write-write Conflict.sql
│ ├── 07.1.Ref Integrity.sql
│ ├── 07.2.Ref Integrity.sql
│ ├── 08.Tran Logging.sql
│ ├── 36.Chapter 36 (Transaction Processing in In-Memory OLTP) (SQL Server 2014).ssmssqlproj
│ └── 36.Chapter 36 (Transaction Processing in In-Memory OLTP) (SQL Server 2016).ssmssqlproj
│ ├── 37.Chapter 37 (In-Memory OLTP Programmability)
│ ├── 01.Loaded Objects.sql
│ ├── 02.1.Atomic Blocks.sql
│ ├── 02.2.Atomic Blocks.sql
│ ├── 03.Natively-compiled functions.sql
│ ├── 04.Execution Statistics.sql
│ ├── 37.Chapter 37 (In-Memory OLTP Programmability) (SQL Server 2014).ssmssqlproj
│ └── 37.Chapter 37 (In-Memory OLTP Programmability) (SQL Server 2016).ssmssqlproj
│ ├── 99.Chapter 99 (System Design Considerations)
│ ├── 01.Implicit Data Type Conversion.sql
│ ├── 02.EF6 Analysis.sql
│ └── 99.Chapter 99 (System Design Considerations).ssmssqlproj
│ ├── SQLServerInternals (SQL Server 2005).ssmssln
│ ├── SQLServerInternals (SQL Server 2008).ssmssln
│ ├── SQLServerInternals (SQL Server 2012).ssmssln
│ ├── SQLServerInternals (SQL Server 2014).ssmssln
│ └── SQLServerInternals (SQL Server 2016).ssmssln
└── contributing.md
/9781484219638.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/9781484219638.jpg
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/LICENSE.txt
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Apress Source Code
2 |
3 | This repository accompanies [*Pro SQL Server Internals*](http://www.apress.com/9781484219638) by Dmitri Korotkevitch (Apress, 2016).
4 |
5 | 
6 |
7 | Download the files as a zip using the green button, or clone the repository to your machine using Git.
8 |
9 | ## Releases
10 |
11 | Release v1.0 corresponds to the code in the published book, without corrections or updates.
12 |
13 | ## Contributions
14 |
15 | See the file Contributing.md for more information on how you can contribute to this repository.
16 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSet.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 11.00
3 | # Visual Studio 2010
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SaveRecordSetApp", "SaveRecordSetApp\SaveRecordSetApp.csproj", "{49EAE681-0A5A-4897-B9A6-AE876CACB201}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|x86 = Debug|x86
9 | Release|x86 = Release|x86
10 | EndGlobalSection
11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 | {49EAE681-0A5A-4897-B9A6-AE876CACB201}.Debug|x86.ActiveCfg = Debug|x86
13 | {49EAE681-0A5A-4897-B9A6-AE876CACB201}.Debug|x86.Build.0 = Debug|x86
14 | {49EAE681-0A5A-4897-B9A6-AE876CACB201}.Release|x86.ActiveCfg = Release|x86
15 | {49EAE681-0A5A-4897-B9A6-AE876CACB201}.Release|x86.Build.0 = Release|x86
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | EndGlobal
21 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/Program.cs:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 13. Temporary Objects and TempDB */
10 | /* Saving Batch of Rows from Client Application */
11 | /****************************************************************************/
12 | using System;
13 | using System.Collections.Generic;
14 | using System.Linq;
15 | using System.Windows.Forms;
16 |
17 | namespace SaveRecordSetApp
18 | {
19 | static class Program
20 | {
21 | ///
22 | /// The main entry point for the application.
23 | ///
24 | [STAThread]
25 | static void Main()
26 | {
27 | Application.EnableVisualStyles();
28 | Application.SetCompatibleTextRenderingDefault(false);
29 | Application.Run(new MainForm());
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("SaveRecordSetApp")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("SaveRecordSetApp")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("99f91cae-13f3-4cd0-9fba-847f0545d42e")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.36366
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace SaveRecordSetApp.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/bin-.Net 3.5/Debug/SaveRecordSetApp.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/bin-.Net 3.5/Debug/SaveRecordSetApp.exe
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/bin-.Net 3.5/Debug/SaveRecordSetApp.exe.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/bin-.Net 3.5/Debug/SaveRecordSetApp.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/bin-.Net 3.5/Debug/SaveRecordSetApp.pdb
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/bin-.Net 3.5/Debug/SaveRecordSetApp.vshost.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/bin-.Net 3.5/Debug/SaveRecordSetApp.vshost.exe
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/bin-.Net 3.5/Debug/SaveRecordSetApp.vshost.exe.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/bin-.Net 3.5/Debug/SaveRecordSetApp.vshost.exe.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/bin-.Net 4.5/Debug/SaveRecordSetApp.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/bin-.Net 4.5/Debug/SaveRecordSetApp.exe
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/bin-.Net 4.5/Debug/SaveRecordSetApp.exe.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/bin-.Net 4.5/Debug/SaveRecordSetApp.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/bin-.Net 4.5/Debug/SaveRecordSetApp.pdb
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/bin-.Net 4.5/Debug/SaveRecordSetApp.vshost.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/bin-.Net 4.5/Debug/SaveRecordSetApp.vshost.exe
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/bin-.Net 4.5/Debug/SaveRecordSetApp.vshost.exe.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/bin-.Net 4.5/Debug/SaveRecordSetApp.vshost.exe.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/obj/x86/Debug/DesignTimeResolveAssemblyReferences.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/obj/x86/Debug/DesignTimeResolveAssemblyReferences.cache
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/obj/x86/Debug/SaveRecordSetApp.Form1.resources:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/obj/x86/Debug/SaveRecordSetApp.Form1.resources
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/obj/x86/Debug/SaveRecordSetApp.MainForm.resources:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/obj/x86/Debug/SaveRecordSetApp.MainForm.resources
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/obj/x86/Debug/SaveRecordSetApp.Properties.Resources.resources:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/obj/x86/Debug/SaveRecordSetApp.Properties.Resources.resources
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/obj/x86/Debug/SaveRecordSetApp.csproj.GenerateResource.Cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/obj/x86/Debug/SaveRecordSetApp.csproj.GenerateResource.Cache
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/obj/x86/Debug/SaveRecordSetApp.csprojResolveAssemblyReference.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/obj/x86/Debug/SaveRecordSetApp.csprojResolveAssemblyReference.cache
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/obj/x86/Debug/SaveRecordSetApp.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/obj/x86/Debug/SaveRecordSetApp.exe
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/obj/x86/Debug/SaveRecordSetApp.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/obj/x86/Debug/SaveRecordSetApp.pdb
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/obj/x86/Debug/TempPE/Properties.Resources.Designer.cs.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/obj/x86/Debug/TempPE/Properties.Resources.Designer.cs.dll
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/obj/x86/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/obj/x86/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/obj/x86/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/obj/x86/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/obj/x86/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/13.Chapter 13 (Temporary Objects and TempDB)/SaveRecordSetApp/obj/x86/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2005/CLRTest.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.21005.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{00D1A9C2-B5F0-4AF3-8072-F6C62B433612}") = "CLRTest", "CLRTest\CLRTest.sqlproj", "{BED20387-7451-4B4E-9E85-AB3A07666814}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {BED20387-7451-4B4E-9E85-AB3A07666814}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {BED20387-7451-4B4E-9E85-AB3A07666814}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {BED20387-7451-4B4E-9E85-AB3A07666814}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
17 | {BED20387-7451-4B4E-9E85-AB3A07666814}.Release|Any CPU.ActiveCfg = Release|Any CPU
18 | {BED20387-7451-4B4E-9E85-AB3A07666814}.Release|Any CPU.Build.0 = Release|Any CPU
19 | {BED20387-7451-4B4E-9E85-AB3A07666814}.Release|Any CPU.Deploy.0 = Release|Any CPU
20 | EndGlobalSection
21 | GlobalSection(SolutionProperties) = preSolution
22 | HideSolutionNode = FALSE
23 | EndGlobalSection
24 | EndGlobal
25 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2005/CLRTest/CLRTest.dbmdl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2005/CLRTest/CLRTest.dbmdl
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2005/CLRTest/CLRTest.sqlproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2005/CLRTest/bin/Debug/CLRTest.dacpac:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2005/CLRTest/bin/Debug/CLRTest.dacpac
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2005/CLRTest/bin/Debug/CLRTest.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2005/CLRTest/bin/Debug/CLRTest.dll
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2005/CLRTest/bin/Debug/CLRTest.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2005/CLRTest/bin/Debug/CLRTest.pdb
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2005/CLRTest/obj/Debug/CLRTest.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2005/CLRTest/obj/Debug/CLRTest.dll
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2005/CLRTest/obj/Debug/CLRTest.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2005/CLRTest/obj/Debug/CLRTest.pdb
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2005/CLRTest/obj/Debug/CLRTest.sqlproj.FileListAbsolute.txt:
--------------------------------------------------------------------------------
1 | E:\Work\Work\VS\CLRTest\CLRTest\bin\Debug\CLRTest.dacpac
2 | E:\Work\Work\VS\CLRTest\CLRTest\bin\Debug\CLRTest_Create.sql
3 | E:\Work\Work\VS\CLRTest\CLRTest\bin\Debug\CLRTest.dll
4 | E:\Work\Work\VS\CLRTest\CLRTest\bin\Debug\CLRTest.pdb
5 | E:\Work\Work\VS\CLRTest\CLRTest\obj\Debug\Model.xml
6 | E:\Work\Work\VS\CLRTest\CLRTest\obj\Debug\refactor.xml
7 | E:\Work\Work\VS\CLRTest\CLRTest\obj\Debug\postdeploy.sql
8 | E:\Work\Work\VS\CLRTest\CLRTest\obj\Debug\predeploy.sql
9 | E:\Work\Work\VS\CLRTest\CLRTest\obj\Debug\CLRTest.dll
10 | E:\Work\Work\VS\CLRTest\CLRTest\obj\Debug\CLRTest.pdb
11 | C:\Work\CLRTest\CLRTest\obj\Debug\CLRTest.dll
12 | C:\Work\CLRTest\CLRTest\bin\Debug\CLRTest.dacpac
13 | C:\Work\CLRTest\CLRTest\bin\Debug\CLRTest_Create.sql
14 | C:\Work\CLRTest\CLRTest\bin\Debug\CLRTest.dll
15 | C:\Work\CLRTest\CLRTest\bin\Debug\CLRTest.pdb
16 | C:\Work\CLRTest\CLRTest\obj\Debug\Model.xml
17 | C:\Work\CLRTest\CLRTest\obj\Debug\refactor.xml
18 | C:\Work\CLRTest\CLRTest\obj\Debug\postdeploy.sql
19 | C:\Work\CLRTest\CLRTest\obj\Debug\predeploy.sql
20 | C:\Work\CLRTest\CLRTest\obj\Debug\CLRTest.pdb
21 | c:\.Net\14.Chapters 14-15 (CLR)\SQL Server 2005\CLRTest\bin\Debug\CLRTest.dacpac
22 | c:\.Net\14.Chapters 14-15 (CLR)\SQL Server 2005\CLRTest\bin\Debug\CLRTest.dll
23 | c:\.Net\14.Chapters 14-15 (CLR)\SQL Server 2005\CLRTest\bin\Debug\CLRTest.pdb
24 | c:\.Net\14.Chapters 14-15 (CLR)\SQL Server 2005\CLRTest\obj\Debug\Model.xml
25 | c:\.Net\14.Chapters 14-15 (CLR)\SQL Server 2005\CLRTest\obj\Debug\refactor.xml
26 | c:\.Net\14.Chapters 14-15 (CLR)\SQL Server 2005\CLRTest\obj\Debug\postdeploy.sql
27 | c:\.Net\14.Chapters 14-15 (CLR)\SQL Server 2005\CLRTest\obj\Debug\predeploy.sql
28 | c:\.Net\14.Chapters 14-15 (CLR)\SQL Server 2005\CLRTest\obj\Debug\CLRTest.dll
29 | c:\.Net\14.Chapters 14-15 (CLR)\SQL Server 2005\CLRTest\obj\Debug\CLRTest.pdb
30 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2008-2008R2/CLRTest.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.21005.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{00D1A9C2-B5F0-4AF3-8072-F6C62B433612}") = "CLRTest", "CLRTest\CLRTest.sqlproj", "{BED20387-7451-4B4E-9E85-AB3A07666814}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {BED20387-7451-4B4E-9E85-AB3A07666814}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {BED20387-7451-4B4E-9E85-AB3A07666814}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {BED20387-7451-4B4E-9E85-AB3A07666814}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
17 | {BED20387-7451-4B4E-9E85-AB3A07666814}.Release|Any CPU.ActiveCfg = Release|Any CPU
18 | {BED20387-7451-4B4E-9E85-AB3A07666814}.Release|Any CPU.Build.0 = Release|Any CPU
19 | {BED20387-7451-4B4E-9E85-AB3A07666814}.Release|Any CPU.Deploy.0 = Release|Any CPU
20 | EndGlobalSection
21 | GlobalSection(SolutionProperties) = preSolution
22 | HideSolutionNode = FALSE
23 | EndGlobalSection
24 | EndGlobal
25 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2008-2008R2/CLRTest/CLRTest.dbmdl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2008-2008R2/CLRTest/CLRTest.dbmdl
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2008-2008R2/CLRTest/CLRTest.sqlproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2008-2008R2/CLRTest/bin/Debug/CLRTest.dacpac:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2008-2008R2/CLRTest/bin/Debug/CLRTest.dacpac
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2008-2008R2/CLRTest/bin/Debug/CLRTest.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2008-2008R2/CLRTest/bin/Debug/CLRTest.dll
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2008-2008R2/CLRTest/bin/Debug/CLRTest.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2008-2008R2/CLRTest/bin/Debug/CLRTest.pdb
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2008-2008R2/CLRTest/obj/Debug/CLRTest.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2008-2008R2/CLRTest/obj/Debug/CLRTest.dll
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2008-2008R2/CLRTest/obj/Debug/CLRTest.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2008-2008R2/CLRTest/obj/Debug/CLRTest.pdb
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2012-2016/CLRTest.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.30110.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{00D1A9C2-B5F0-4AF3-8072-F6C62B433612}") = "CLRTest", "CLRTest\CLRTest.sqlproj", "{BED20387-7451-4B4E-9E85-AB3A07666814}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {BED20387-7451-4B4E-9E85-AB3A07666814}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {BED20387-7451-4B4E-9E85-AB3A07666814}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {BED20387-7451-4B4E-9E85-AB3A07666814}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
17 | {BED20387-7451-4B4E-9E85-AB3A07666814}.Release|Any CPU.ActiveCfg = Release|Any CPU
18 | {BED20387-7451-4B4E-9E85-AB3A07666814}.Release|Any CPU.Build.0 = Release|Any CPU
19 | {BED20387-7451-4B4E-9E85-AB3A07666814}.Release|Any CPU.Deploy.0 = Release|Any CPU
20 | EndGlobalSection
21 | GlobalSection(SolutionProperties) = preSolution
22 | HideSolutionNode = FALSE
23 | EndGlobalSection
24 | EndGlobal
25 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2012-2016/CLRTest/CLRTest.dbmdl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2012-2016/CLRTest/CLRTest.dbmdl
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2012-2016/CLRTest/CLRTest.sqlproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2012-2016/CLRTest/bin/Debug/CLRTest.dacpac:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2012-2016/CLRTest/bin/Debug/CLRTest.dacpac
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2012-2016/CLRTest/bin/Debug/CLRTest.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2012-2016/CLRTest/bin/Debug/CLRTest.dll
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2012-2016/CLRTest/bin/Debug/CLRTest.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2012-2016/CLRTest/bin/Debug/CLRTest.pdb
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2012-2016/CLRTest/obj/Debug/CLRTest.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2012-2016/CLRTest/obj/Debug/CLRTest.dll
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2012-2016/CLRTest/obj/Debug/CLRTest.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/pro-sql-server-internals-2ed/181aca74c1de1f91dc0776ef9b13df537bbdd4b6/SQL Server Internals 2nd Edition/.Net/14.Chapters 14-15 (CLR)/SQL Server 2012-2016/CLRTest/obj/Debug/CLRTest.pdb
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/99.Chapter 99 (System Design Considerations)/EF6/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/99.Chapter 99 (System Design Considerations)/EF6/EFDbContext.cs:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 1st Edition. ISBN-13: 978-1430259626 ISBN-10:1430259620 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dmitri@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 16. System Design Considerations */
10 | /* C# code written by Maxim Alexeyev */
11 | /* http://discoveringdotnet.alexeyev.org */
12 | /****************************************************************************/
13 | using System;
14 | using System.Collections.Generic;
15 | using System.Data.Entity;
16 | using System.Data.Entity.ModelConfiguration.Conventions;
17 | using System.Linq;
18 | using System.Text;
19 | using System.Threading.Tasks;
20 | using ORMTests.EF6.Mapping;
21 | using ORMTests.Model;
22 |
23 | namespace ORMTests.EF6
24 | {
25 | public class EFDbContext : DbContext
26 | {
27 | public EFDbContext()
28 | : base("ORMTest")
29 | {
30 | Configuration.UseDatabaseNullSemantics = true;
31 |
32 | }
33 |
34 | public DbSet Customers { get; set; }
35 |
36 | public DbSet Orders { get; set; }
37 |
38 | public DbSet OrderItems { get; set; }
39 |
40 | protected override void OnModelCreating(DbModelBuilder modelBuilder)
41 | {
42 | base.OnModelCreating(modelBuilder);
43 | modelBuilder.HasDefaultSchema("ef6");
44 | modelBuilder.Configurations.Add(new CustomerMap());
45 | modelBuilder.Configurations.Add(new OrderMap());
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/99.Chapter 99 (System Design Considerations)/EF6/Mapping/CustomerMap.cs:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 1st Edition. ISBN-13: 978-1430259626 ISBN-10:1430259620 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dmitri@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 16. System Design Considerations */
10 | /* C# code written by Maxim Alexeyev */
11 | /* http://discoveringdotnet.alexeyev.org */
12 | /****************************************************************************/
13 |
14 | using System;
15 | using System.Collections.Generic;
16 | using System.ComponentModel.DataAnnotations.Schema;
17 | using System.Data.Entity.ModelConfiguration;
18 | using System.Linq;
19 | using System.Text;
20 | using System.Threading.Tasks;
21 | using ORMTests.Model;
22 |
23 | namespace ORMTests.EF6.Mapping
24 | {
25 | internal class CustomerMap : EntityTypeConfiguration
26 | {
27 | public CustomerMap()
28 | {
29 | HasKey(t => t.CustomerId);
30 | Property(t => t.FirstName).HasMaxLength(235);
31 | Property(t => t.LastName).HasMaxLength(255);
32 | Property(t => t.CustomerId).HasColumnType("int");
33 | Property(t => t.CreditLimit).HasColumnType("int");
34 | Property(t => t.LastPurchaseDate).HasColumnType("datetime");
35 | Property(t => t.Email).IsUnicode(false);
36 | Property(t => t.Email).HasMaxLength(254);
37 | Property(t => t.Ver)
38 | .IsConcurrencyToken()
39 | .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed);
40 | }
41 |
42 |
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/99.Chapter 99 (System Design Considerations)/EF6/Mapping/OrderMap.cs:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 1st Edition. ISBN-13: 978-1430259626 ISBN-10:1430259620 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dmitri@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 16. System Design Considerations */
10 | /* C# code written by Maxim Alexeyev */
11 | /* http://discoveringdotnet.alexeyev.org */
12 | /****************************************************************************/
13 | using System;
14 | using System.Collections.Generic;
15 | using System.Data.Entity.ModelConfiguration;
16 | using System.Linq;
17 | using System.Text;
18 | using System.Threading.Tasks;
19 | using ORMTests.Model;
20 |
21 | namespace ORMTests.EF6.Mapping
22 | {
23 | internal class OrderMap : EntityTypeConfiguration
24 | {
25 | public OrderMap()
26 | {
27 | HasKey(t => t.OrderId);
28 | Property(t => t.OrderNo).HasMaxLength(50);
29 | }
30 |
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/99.Chapter 99 (System Design Considerations)/EF6/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("EF6")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("EF6")]
13 | [assembly: AssemblyCopyright("Copyright © 2013")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("3c345eb1-be7c-4850-a70d-dd469fa3c9a1")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/99.Chapter 99 (System Design Considerations)/EF6/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/99.Chapter 99 (System Design Considerations)/Model/Customer.cs:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 1st Edition. ISBN-13: 978-1430259626 ISBN-10:1430259620 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dmitri@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 16. System Design Considerations */
10 | /* C# code written by Maxim Alexeyev */
11 | /* http://discoveringdotnet.alexeyev.org */
12 | /****************************************************************************/
13 | using System;
14 | using System.Collections.Generic;
15 | using System.ComponentModel.DataAnnotations;
16 | using System.Linq;
17 | using System.Text;
18 | using System.Threading.Tasks;
19 |
20 | namespace ORMTests.Model
21 | {
22 | public class Customer
23 | {
24 | public Customer()
25 | {
26 | Orders = new HashSet();
27 | }
28 |
29 | public int CustomerId { get; set; }
30 |
31 | public string FirstName { get; set; }
32 |
33 | public string LastName { get; set; }
34 |
35 | public string Email { get; set; }
36 |
37 | public DateTime Created { get; set; }
38 |
39 | public DateTime Modified { get; set; }
40 |
41 | public DateTime? LastPurchaseDate { get; set; }
42 |
43 | public int? CreditLimit { get; set; }
44 |
45 | //[Timestamp]
46 | public byte[] Ver { get; set; }
47 |
48 | public virtual ICollection Orders { get; set; }
49 |
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/99.Chapter 99 (System Design Considerations)/Model/Order.cs:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 1st Edition. ISBN-13: 978-1430259626 ISBN-10:1430259620 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dmitri@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 16. System Design Considerations */
10 | /* C# code written by Maxim Alexeyev */
11 | /* http://discoveringdotnet.alexeyev.org */
12 | /****************************************************************************/
13 | using System;
14 | using System.Collections.Generic;
15 | using System.Linq;
16 | using System.Text;
17 | using System.Threading.Tasks;
18 |
19 | namespace ORMTests.Model
20 | {
21 | public class Order
22 | {
23 | public Order()
24 | {
25 | Items = new HashSet();
26 | }
27 |
28 | public int OrderId { get; set; }
29 |
30 | public int CustomerId { get; set; }
31 |
32 | public virtual Customer Customer { get; set; }
33 |
34 | public string OrderNo { get; set; }
35 |
36 | public DateTime Created { get; set; }
37 |
38 | public DateTime Modified { get; set; }
39 |
40 | public virtual ICollection Items { get; set; }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/99.Chapter 99 (System Design Considerations)/Model/OrderItem.cs:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 1st Edition. ISBN-13: 978-1430259626 ISBN-10:1430259620 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dmitri@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 16. System Design Considerations */
10 | /* C# code written by Maxim Alexeyev */
11 | /* http://discoveringdotnet.alexeyev.org */
12 | /****************************************************************************/
13 | using System;
14 | using System.Collections.Generic;
15 | using System.Linq;
16 | using System.Text;
17 | using System.Threading.Tasks;
18 |
19 | namespace ORMTests.Model
20 | {
21 | public class OrderItem
22 | {
23 | public int OrderId { get; set; }
24 |
25 | public virtual Order Order { get; set; }
26 |
27 | public int OrderItemId { get; set; }
28 |
29 | public double Qty { get; set; }
30 |
31 | public decimal Price { get; set; }
32 |
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/99.Chapter 99 (System Design Considerations)/Model/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Model")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Model")]
13 | [assembly: AssemblyCopyright("Copyright © 2013")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("1c2f9fb5-1627-4b94-9a3e-160d2408901c")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/99.Chapter 99 (System Design Considerations)/ORMTests.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.30110.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ORMTests", "ORMTests\ORMTests.csproj", "{6C83E583-62FE-4634-B9FA-A567D6196269}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EF6", "EF6\EF6.csproj", "{3A7F3935-A464-4502-A327-6B25EE964329}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model", "Model\Model.csproj", "{241546D4-4730-4FE8-A928-42CD1401B4B4}"
11 | EndProject
12 | Global
13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
14 | Debug|Any CPU = Debug|Any CPU
15 | Release|Any CPU = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {6C83E583-62FE-4634-B9FA-A567D6196269}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 | {6C83E583-62FE-4634-B9FA-A567D6196269}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 | {6C83E583-62FE-4634-B9FA-A567D6196269}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 | {6C83E583-62FE-4634-B9FA-A567D6196269}.Release|Any CPU.Build.0 = Release|Any CPU
22 | {3A7F3935-A464-4502-A327-6B25EE964329}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 | {3A7F3935-A464-4502-A327-6B25EE964329}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 | {3A7F3935-A464-4502-A327-6B25EE964329}.Release|Any CPU.ActiveCfg = Release|Any CPU
25 | {3A7F3935-A464-4502-A327-6B25EE964329}.Release|Any CPU.Build.0 = Release|Any CPU
26 | {241546D4-4730-4FE8-A928-42CD1401B4B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {241546D4-4730-4FE8-A928-42CD1401B4B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {241546D4-4730-4FE8-A928-42CD1401B4B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {241546D4-4730-4FE8-A928-42CD1401B4B4}.Release|Any CPU.Build.0 = Release|Any CPU
30 | EndGlobalSection
31 | GlobalSection(SolutionProperties) = preSolution
32 | HideSolutionNode = FALSE
33 | EndGlobalSection
34 | EndGlobal
35 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/99.Chapter 99 (System Design Considerations)/ORMTests/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/99.Chapter 99 (System Design Considerations)/ORMTests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("ORMTests")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("ORMTests")]
13 | [assembly: AssemblyCopyright("Copyright © 2013")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("800c7b1e-ada1-4f30-aa6d-adc520bb9f9f")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/.Net/99.Chapter 99 (System Design Considerations)/ORMTests/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/00.Init/00.Init (SQL Server 2014-2016).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.DB Creation.sql
14 |
15 |
16 |
17 |
18 |
19 | 02.Create In-Memory OLTP DB.sql
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/00.Init/00.Init.ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.DB Creation.sql
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/01.Chapter 01 (Data Storage Internals)/01.Chapter 01 (Data Storage Internals).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.Check Instant File Initialization.sql
14 |
15 |
16 |
17 |
18 |
19 | 02.Data Row Format.sql
20 |
21 |
22 |
23 |
24 |
25 | 03.Select and IO.sql
26 |
27 |
28 |
29 |
30 |
31 | 04.Row size and Performance.sql
32 |
33 |
34 |
35 |
36 |
37 | 05.Alteration.sql
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/01.Chapter 01 (Data Storage Internals)/01.Check Instant File Initialization.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 01. Data Storage Internals */
10 | /* Check if Instant File Initialization is Enabled */
11 | /****************************************************************************/
12 |
13 | use master
14 | go
15 |
16 | /*** Checking to see if Instant File Initialization is enabled ***/
17 | dbcc traceon(3004,3605,-1)
18 | go
19 |
20 | create database Dummy
21 | go
22 |
23 | exec sp_readerrorlog
24 | go
25 |
26 | drop database Dummy
27 | go
28 |
29 | dbcc traceoff(3004,3605,-1)
30 | go
31 |
32 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/01.Chapter 01 (Data Storage Internals)/03.Select and IO.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 01. Data Storage Internals */
10 | /* SELECT * and I/O */
11 | /****************************************************************************/
12 |
13 | use [SqlServerInternals]
14 | go
15 |
16 |
17 | if exists(select * from sys.tables t join sys.schemas s on t.schema_id = s.schema_id where s.name = 'dbo' and t.name = 'Employees') drop table dbo.Employees;
18 | go
19 |
20 | create table dbo.Employees
21 | (
22 | EmployeeId int not null,
23 | Name varchar(128) not null,
24 | Picture varbinary(max) null
25 | );
26 |
27 | ;with N1(C) as (select 0 union all select 0) -- 2 rows
28 | ,N2(C) as (select 0 from N1 as T1 cross join N1 as T2) -- 4 rows
29 | ,N3(C) as (select 0 from N2 as T1 cross join N2 as T2) -- 16 rows
30 | ,N4(C) as (select 0 from N3 as T1 cross join N3 as T2) -- 256 rows
31 | ,N5(C) as (select 0 from N4 as T1 cross join N2 as T2) -- 1,024 rows
32 | ,IDs(ID) as (select row_number() over (order by (select NULL)) from N5)
33 | insert into dbo.Employees(EmployeeId, Name, Picture)
34 | select
35 | ID, 'Employee ' + convert(varchar(5),ID),
36 | convert(varbinary(max),replicate(convert(varchar(max),'a'),120000))
37 | from Ids;
38 | go
39 |
40 | set statistics io, time on
41 |
42 | select * from dbo.Employees;
43 | select EmployeeId, Name from dbo.Employees;
44 |
45 | set statistics io, time off
46 | go
47 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/02.Chapter 02 (Tables and Indexes)/01.Heaps and PFS.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 02. Tables and Indexes: Internal Structure and Access Methods */
10 | /* Heap Tables and PFS */
11 | /****************************************************************************/
12 |
13 | use [SqlServerInternals]
14 | go
15 |
16 | if exists(select * from sys.tables t join sys.schemas s on t.schema_id = s.schema_id where s.name = 'dbo' and t.name = 'Heap') drop table dbo.Heap;
17 | go
18 |
19 | create table dbo.Heap
20 | (
21 | Val varchar(8000) not null
22 | );
23 |
24 | ;with CTE(ID,Val)
25 | as
26 | (
27 | select 1, replicate('0',4089)
28 | union all
29 | select ID + 1, Val from CTE where ID < 20
30 | )
31 | insert into dbo.Heap
32 | select Val from CTE;
33 | go
34 |
35 | select page_count, avg_record_size_in_bytes, avg_page_space_used_in_percent
36 | from sys.dm_db_index_physical_stats(db_id(),object_id(N'dbo.Heap'),0,null,'DETAILED');
37 |
38 | insert into dbo.Heap(Val) values(replicate('1',100));
39 |
40 | select page_count, avg_record_size_in_bytes, avg_page_space_used_in_percent
41 | from sys.dm_db_index_physical_stats(db_id(),object_id(N'dbo.Heap'),0,null,'DETAILED');
42 |
43 | insert into dbo.Heap(Val) values(replicate('2',2000));
44 |
45 | select page_count, avg_record_size_in_bytes, avg_page_space_used_in_percent
46 | from sys.dm_db_index_physical_stats(db_id(),object_id(N'dbo.Heap'),0,null,'DETAILED');
47 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/02.Chapter 02 (Tables and Indexes)/02.Chapter 02 (Tables and Indexes) (SQL Server 2016).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.Heaps and PFS.sql
14 |
15 |
16 |
17 |
18 |
19 | 02.Forwarding Pointers.sql
20 |
21 |
22 |
23 |
24 |
25 | 03.SARGability and Data Types.sql
26 |
27 |
28 |
29 |
30 |
31 | 04.Max NCI Key Size (SQL Server 2016).sql
32 |
33 |
34 |
35 |
36 |
37 | 05.Nonclustered Index Usage.sql
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/02.Chapter 02 (Tables and Indexes)/02.Chapter 02 (Tables and Indexes).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.Heaps and PFS.sql
14 |
15 |
16 |
17 |
18 |
19 | 02.Forwarding Pointers.sql
20 |
21 |
22 |
23 |
24 |
25 | 03.SARGability and Data Types.sql
26 |
27 |
28 |
29 |
30 |
31 | 04.Max NCI Key Size.sql
32 |
33 |
34 |
35 |
36 |
37 | 05.Nonclustered Index Usage.sql
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/02.Chapter 02 (Tables and Indexes)/04.Max NCI Key Size (SQL Server 2016).sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 02. Tables and Indexes: Internal Structure and Access Methods */
10 | /* Nonclustered Index Key Size Limitation (SQL Server 2016) */
11 | /****************************************************************************/
12 |
13 | use [SqlServerInternals]
14 | go
15 |
16 | if exists(select * from sys.tables t join sys.schemas s on t.schema_id = s.schema_id where s.name = 'dbo' and t.name = 'LargeKeys') drop table dbo.LargeKeys;
17 | go
18 |
19 | create table dbo.LargeKeys
20 | (
21 | Col1 varchar(1000) not null,
22 | Col2 varchar(1000) not null
23 | );
24 |
25 | -- Success with the warining
26 | create nonclustered index IDX_NCI on dbo.LargeKeys(Col1,Col2);
27 | go
28 |
29 | -- Success:
30 | insert into dbo.LargeKeys(Col1, Col2) values('Small','Small');
31 | go
32 |
33 | -- Failure:
34 | insert into dbo.LargeKeys(Col1, Col2) values(replicate('A',900),replicate('B',900));
35 | go
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/02.Chapter 02 (Tables and Indexes)/04.Max NCI Key Size.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 02. Tables and Indexes: Internal Structure and Access Methods */
10 | /* Nonclustered Index Key Size Limitation (SQL Server 2005-2014) */
11 | /****************************************************************************/
12 |
13 | use [SqlServerInternals]
14 | go
15 |
16 | if exists(select * from sys.tables t join sys.schemas s on t.schema_id = s.schema_id where s.name = 'dbo' and t.name = 'LargeKeys') drop table dbo.LargeKeys;
17 | go
18 |
19 | create table dbo.LargeKeys
20 | (
21 | Col1 varchar(500) not null,
22 | Col2 varchar(500) not null
23 | );
24 |
25 | -- Success with the warining
26 | create nonclustered index IDX_NCI on dbo.LargeKeys(Col1,Col2);
27 | go
28 |
29 | -- Success:
30 | insert into dbo.LargeKeys(Col1, Col2) values('Small','Small');
31 | go
32 |
33 | -- Failure:
34 | insert into dbo.LargeKeys(Col1, Col2) values(replicate('A',500),replicate('B',500));
35 | go
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/03.Chapter 03 (Statistics)/03.Chapter 03 (Statistics) (SQL Server 2014).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.Exploring Statistics.sql
14 |
15 |
16 |
17 |
18 |
19 | 02.Column-level Statistics.sql
20 |
21 |
22 |
23 |
24 |
25 | 03.Statistics and Exec Plans.sql
26 |
27 |
28 |
29 |
30 |
31 | 04.Statistics and Memory Grants.sql
32 |
33 |
34 |
35 |
36 |
37 | 05.SQL Server 2014-2016 Cardinality Estimators.sql
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/03.Chapter 03 (Statistics)/03.Chapter 03 (Statistics) (SQL Server 2016).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.Exploring Statistics.sql
14 |
15 |
16 |
17 |
18 |
19 | 02.Column-level Statistics.sql
20 |
21 |
22 |
23 |
24 |
25 | 03.Statistics and Exec Plans.sql
26 |
27 |
28 |
29 |
30 |
31 | 04.Statistics and Memory Grants.sql
32 |
33 |
34 |
35 |
36 |
37 | 05.SQL Server 2016 Cardinality Estimator.sql
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/03.Chapter 03 (Statistics)/03.Chapter 03 (Statistics).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.Exploring Statistics.sql
14 |
15 |
16 |
17 |
18 |
19 | 02.Column-level Statistics.sql
20 |
21 |
22 |
23 |
24 |
25 | 03.Statistics and Exec Plans.sql
26 |
27 |
28 |
29 |
30 |
31 | 04.Statistics and Memory Grants.sql
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/04.Chapter 04 (Special Features)/04.Chapter 04 (Special Features) (SQL Server 2005).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.Included Columns.sql
14 |
15 |
16 |
17 |
18 |
19 | 04.Calculated Columns.sql
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/05.Chapter 05 (SQL Server 2016 Features)/05.Chapter 05 (SQL Server 2016 Features).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.Temporal Tables.sql
14 |
15 |
16 |
17 |
18 |
19 | 02.Stretch Databases.sql
20 |
21 |
22 |
23 |
24 |
25 | 03.RLS.sql
26 |
27 |
28 |
29 |
30 |
31 | 04.Dynamic Data Masking.sql
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/06.Chapter 06 (Index Fragmentation)/06.Chapter 06 (Index Fragmentation).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.Page Splits.sql
14 |
15 |
16 |
17 |
18 |
19 | 02.Row Size Increase on Update.sql
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/08.Chapter 08 (Constraints)/08.Chapter 08 (Constraints).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.FK.sql
14 |
15 |
16 |
17 |
18 |
19 | 02.Check Constraints Overhead.sql
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/09.Chapter 09 (Triggers)/03.DDL Triggers.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 09. Triggers */
10 | /* DDL Triggers */
11 | /****************************************************************************/
12 |
13 | use [SqlServerInternals]
14 | go
15 |
16 | if exists(select * from sys.triggers where name = 'trg_PreventAlterDropTable') drop trigger trg_PreventAlterDropTable on database;
17 | if exists(select * from sys.tables t join sys.schemas s on t.schema_id = s.schema_id where s.name = 'dbo' and t.name = 'Test') drop table dbo.Test;
18 | go
19 |
20 | create table dbo.Test(ID int);
21 | go
22 |
23 | create trigger trg_PreventAlterDropTable on database
24 | for alter_table, drop_table
25 | as
26 | begin
27 | declare
28 | @objName nvarchar(257);
29 | select @objName =
30 | eventdata().value('/EVENT_INSTANCE[1]/SchemaName[1]','nvarchar(128)') +
31 | '.' + eventdata().value('/EVENT_INSTANCE[1]/ObjectName[1]','nvarchar(128)');
32 |
33 | select column_id, name
34 | from sys.columns
35 | where object_id = object_id(@objName);
36 |
37 | print 'Table cannot be altered or dropped with trgPreventAlterDropTable trigger enabled'
38 | rollback;
39 | end
40 | go
41 |
42 | -- Failed
43 | alter table dbo.Test add Col1 int;
44 | go
45 |
46 | -- Clean-up
47 | drop trigger trg_PreventAlterDropTable on database;
48 | go
49 |
50 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/09.Chapter 09 (Triggers)/09.Chapter 09 (Triggers) (SQL Server 2005).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 02.Triggers and Fragmentation.sql
14 |
15 |
16 |
17 |
18 |
19 | 03.DDL Triggers.sql
20 |
21 |
22 |
23 |
24 |
25 | 04.Context_Info.sql
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/09.Chapter 09 (Triggers)/09.Chapter 09 (Triggers) (SQL Server 2016).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.Merge.sql
14 |
15 |
16 |
17 |
18 |
19 | 02.Triggers and Fragmentation.sql
20 |
21 |
22 |
23 |
24 |
25 | 03.DDL Triggers.sql
26 |
27 |
28 |
29 |
30 |
31 | 04.Context_Info.sql
32 |
33 |
34 |
35 |
36 |
37 | 05.Session Context.sql
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/09.Chapter 09 (Triggers)/09.Chapter 09 (Triggers).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.Merge.sql
14 |
15 |
16 |
17 |
18 |
19 | 02.Triggers and Fragmentation.sql
20 |
21 |
22 |
23 |
24 |
25 | 03.DDL Triggers.sql
26 |
27 |
28 |
29 |
30 |
31 | 04.Context_Info.sql
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/10.Chapter 10 (Views)/05.CHECK Option.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 10. Views */
10 | /* Views with CHECK OPTION */
11 | /****************************************************************************/
12 |
13 | use [SqlServerInternals]
14 | go
15 |
16 | if exists(select * from sys.views v join sys.schemas s on v.schema_id = s.schema_id where s.name = 'dbo' and v.name = 'vPositiveNumbers') drop view dbo.vPositiveNumbers;
17 | if exists(select * from sys.tables t join sys.schemas s on t.schema_id = s.schema_id where s.name = 'dbo' and t.name = 'Numbers') drop table dbo.Numbers;
18 | go
19 |
20 | create table dbo.Numbers(Number int)
21 | go
22 |
23 | create view dbo.vPositiveNumbers(Number)
24 | as
25 | select Number
26 | from dbo.Numbers
27 | where Number > 0
28 | with check option;
29 | go
30 |
31 | -- Success
32 | insert into dbo.vPositiveNumbers(Number) values(1);
33 | go
34 |
35 | -- Failure
36 | insert into dbo.vPositiveNumbers(Number) values(-1);
37 | go
38 |
39 | -- Failure
40 | update dbo.vPositiveNumbers set Number = -1 where Number = 1;
41 | go
42 |
43 | select * from dbo.Numbers;
44 | go
45 |
46 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/10.Chapter 10 (Views)/10.Chapter 10 (Views).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.Join Elimination (Single-column join).sql
14 |
15 |
16 |
17 |
18 |
19 | 02.Join Elimination (Multi-column join).sql
20 |
21 |
22 |
23 |
24 |
25 | 03.Indexed Views.sql
26 |
27 |
28 |
29 |
30 |
31 | 04.Supporting Uniqueness with Indexed Views.sql
32 |
33 |
34 |
35 |
36 |
37 | 05.CHECK Option.sql
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/11.Chapter 11 (Functions)/11.Chapter 11 (Functions) (SQL Server 2005).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 02.Scalar UDF.sql
14 |
15 |
16 |
17 |
18 |
19 | 03.Multi-statement UDF.sql
20 |
21 |
22 |
23 |
24 |
25 | 03.Optimizing with CTE.sql
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/11.Chapter 11 (Functions)/11.Chapter 11 (Functions).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.Code Reuse.sql
14 |
15 |
16 |
17 |
18 |
19 | 02.Scalar UDF.sql
20 |
21 |
22 |
23 |
24 |
25 | 03.Multi-statement UDF.sql
26 |
27 |
28 |
29 |
30 |
31 | 03.Optimizing with CTE.sql
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/12.Chapter 12 (XML and JSON)/12.Chapter 12 (XML and JSON) (SQL Server 2016).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.Primary XML Index.sql
14 |
15 |
16 |
17 |
18 |
19 | 02.XML Storage Space.sql
20 |
21 |
22 |
23 |
24 |
25 | 03.Working with XML.sql
26 |
27 |
28 |
29 |
30 |
31 | 04.FOR XML.sql
32 |
33 |
34 |
35 |
36 |
37 | 05.Working With JSON.sql
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/12.Chapter 12 (XML and JSON)/12.Chapter 12 (XML and JSON).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.Primary XML Index.sql
14 |
15 |
16 |
17 |
18 |
19 | 02.XML Storage Space.sql
20 |
21 |
22 |
23 |
24 |
25 | 03.Working with XML.sql
26 |
27 |
28 |
29 |
30 |
31 | 04.FOR XML.sql
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/13.Chapter 13 (Temporary Objects and TempDb)/03.Temp Table Caching.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 13. Temporary Objects and TempDB */
10 | /* Temporary Tables Caching */
11 | /****************************************************************************/
12 |
13 | set nocount on
14 | go
15 |
16 | /* Run in context of tempdb */
17 | use [tempdb]
18 | go
19 |
20 | if exists(select * from sys.procedures p join sys.schemas s on p.schema_id = s.schema_id where s.name = 'dbo' and p.name = 'TempTableCaching') drop proc dbo.TempTableCaching;
21 | go
22 |
23 | create proc dbo.TempTableCaching
24 | as
25 | create table #T(C int not null primary key);
26 | drop table #T ;
27 | go
28 |
29 | /* Check Number of Operations logged */
30 | checkpoint
31 | go
32 |
33 | exec dbo.TempTableCaching;
34 | go
35 |
36 | select Operation, Context, AllocUnitName, [Transaction Name], [Description]
37 | from sys.fn_dblog(null, null);
38 | go
39 |
40 | checkpoint
41 | go
42 |
43 | exec dbo.TempTableCaching;
44 | go
45 |
46 | select Operation, Context, AllocUnitName, [Transaction Name], [Description]
47 | from sys.fn_dblog(null, null);
48 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/13.Chapter 13 (Temporary Objects and TempDb)/05.Table Variables and Transactions.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 13. Temporary Objects and TempDB */
10 | /* Table Variables and Transactions */
11 | /****************************************************************************/
12 |
13 | /*** Statement-Level Rollback ***/
14 | declare
15 | @T table(ID int not null primary key)
16 |
17 | -- Success
18 | insert into @T(ID) values(1);
19 |
20 | -- Error: primary key violation
21 | --insert into @T(ID) values(2),(3),(3)
22 | insert into @T(ID)
23 | select 2 union all select 3 union all select 3;
24 |
25 | -- 1 row
26 | select * from @T;
27 | go
28 |
29 | /*** Transaction rollback ***/
30 | declare
31 | @Errors table
32 | (
33 | RecId int not null,
34 | [Error] nvarchar(512) not null,
35 |
36 | primary key(RecId)
37 | )
38 | ;
39 | begin tran
40 | -- Insert error information
41 | insert into @Errors(RecId, [Error])
42 | values(11,'Price mistake');
43 |
44 | insert into @Errors(RecId, [Error])
45 | values(42,'Insufficient stock');
46 | rollback
47 | /* Do something with errors */
48 | select RecId, [Error] from @Errors;
49 | go
50 |
51 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/13.Chapter 13 (Temporary Objects and TempDb)/06.TVP Scope.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 13. Temporary Objects and TempDB */
10 | /* TVP Scope */
11 | /****************************************************************************/
12 |
13 | set nocount on
14 | go
15 |
16 | use [SqlServerInternals]
17 | go
18 |
19 | if exists(select * from sys.procedures p join sys.schemas s on p.schema_id = s.schema_id where s.name = 'dbo' and p.name = 'TvpDemo') drop proc dbo.TvpDemo;
20 | if exists(select * from sys.types t join sys.schemas s on t.schema_id = s.schema_id where s.name = 'dbo' and t.name = 'tvpErrors') drop type dbo.tvpErrors;
21 | go
22 |
23 | create type dbo.tvpErrors as table
24 | (
25 | RecId int not null,
26 | [Error] nvarchar(512) not null,
27 | primary key(RecId)
28 | )
29 | go
30 |
31 | create proc dbo.TvpDemo
32 | (
33 | @Errors dbo.tvpErrors readonly
34 | )
35 | as
36 | select RecId, [Error] from @Errors;
37 |
38 | exec sp_executesql
39 | N'select RecId, [Error] from @Err'
40 | ,N'@Err dbo.tvpErrors readonly'
41 | ,@Err = @Errors;
42 | go
43 |
44 | declare
45 | @Errors dbo.tvpErrors
46 |
47 | insert into @Errors(RecId, [Error])
48 | values
49 | (11,'Price mistake'),
50 | (42,'Insufficient stock');
51 |
52 | exec dbo.TvpDemo @Errors;
53 | go
54 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/14.Chapter 14 (CLR)/07.Non-Yelding CLR.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 14. CLR */
10 | /* Non-Yelding CLR code */
11 | /****************************************************************************/
12 |
13 | set nocount on
14 | go
15 |
16 | use [SqlServerInternals]
17 | go
18 |
19 | /****************************************************************************/
20 | /* That script uses objects created by "01.Object Creation.sql" script */
21 | /****************************************************************************/
22 |
23 | exec dbo.EndlessLoop;
24 | go
25 |
26 |
27 | /*** Run in another session ***/
28 | select
29 | er.session_id, ct.forced_yield_count,
30 | w.task_address, w.[state], w.last_wait_type, ct.state
31 | from
32 | sys.dm_clr_tasks ct with (nolock) join
33 | sys.dm_os_workers w with (nolock) on
34 | ct.sos_task_address = w.task_address
35 | join sys.dm_exec_requests er with (nolock) on
36 | w.task_address = er.task_address
37 | where
38 | ct.type = 'E_TYPE_USER'
39 | option (recompile);
40 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/15.Chapter 15 (CLR Types)/15.Chapter 15 (CLR Types) (SQL Server 2005).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.UDT.sql
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/15.Chapter 15 (CLR Types)/15.Chapter 15 (CLR Types).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.UDT.sql
14 |
15 |
16 |
17 |
18 |
19 | 02.Spatital.sql
20 |
21 |
22 |
23 |
24 |
25 | 03.Bounding Box.sql
26 |
27 |
28 |
29 |
30 |
31 | 04.HierarchyId.sql
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/17.Chapter 17 (Lock Types)/01.(X) and (IX) locks.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 17. Lock Types */
10 | /* Exclusive (X) and Intent Exclusive (IX) Locks */
11 | /****************************************************************************/
12 |
13 | use [SqlServerInternals]
14 | go
15 |
16 | /****************************************************************************/
17 | /* That script uses the objects created in "01.DB Creation.sql" script */
18 | /* from 00.Init project */
19 | /****************************************************************************/
20 |
21 |
22 | set transaction isolation level read uncommitted
23 | begin tran
24 | update Delivery.Orders
25 | set Reference = 'New Reference'
26 | where OrderId = 100;
27 |
28 | select resource_type, resource_description,
29 | request_type, request_mode, request_status
30 | from sys.dm_tran_locks
31 | where request_session_id = @@spid;
32 | rollback
33 | go
34 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/17.Chapter 17 (Lock Types)/02.(U) locks.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 17. Lock Types */
10 | /* Update (U) Locks */
11 | /****************************************************************************/
12 |
13 | use [SqlServerInternals]
14 | go
15 |
16 | /****************************************************************************/
17 | /* That script uses the objects created in "01.DB Creation.sql" script */
18 | /* from 00.Init project */
19 | /****************************************************************************/
20 |
21 |
22 | --- Run SQL Profiler or Extended Events and monitor Lock Acquired/Lock
23 | --- Released events filtering by @@SPID
24 |
25 | set transaction isolation level read uncommitted
26 | begin tran
27 | -- Plan with Clustered Index Seek
28 | update Delivery.Orders
29 | set Reference = 'New Reference'
30 | where OrderId in (1000, 5000);
31 | rollback
32 | go
33 |
34 | set transaction isolation level read uncommitted
35 | begin tran
36 | -- Plan with Clustered Index Scan
37 | update Delivery.Orders
38 | set Reference = 'New Reference'
39 | where OrderNum = '1000';
40 | rollback
41 | go
42 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/17.Chapter 17 (Lock Types)/03.1.(S) Locks.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 17. Lock Types */
10 | /* Shared (S) Locks (Session 1) */
11 | /****************************************************************************/
12 |
13 | use [SqlServerInternals]
14 | go
15 |
16 | /****************************************************************************/
17 | /* That script uses the objects created in "01.DB Creation.sql" script */
18 | /* from 00.Init project */
19 | /****************************************************************************/
20 |
21 | set transaction isolation level repeatable read
22 | begin tran
23 | select 'Session 1:', OrderNum
24 | from Delivery.Orders
25 | where OrderId = 500;
26 |
27 | -- Run Session 2 code
28 | commit
29 | go
30 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/17.Chapter 17 (Lock Types)/03.2.(S) Locks.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 17. Lock Types */
10 | /* Shared (S) Locks (Session 2) */
11 | /****************************************************************************/
12 |
13 | use [SqlServerInternals]
14 | go
15 |
16 | /****************************************************************************/
17 | /* That script uses the objects created in "01.DB Creation.sql" script */
18 | /* from 00.Init project */
19 | /****************************************************************************/
20 |
21 |
22 | -- Run Session 1 code without committing transaction
23 | set transaction isolation level repeatable read
24 | begin tran
25 | select 'Session 2:', OrderDate
26 | from Delivery.Orders
27 | where OrderId = 500;
28 |
29 | select request_session_id,
30 | resource_type, resource_description,
31 | request_type, request_mode, request_status
32 | from sys.dm_tran_locks
33 | where request_session_id in (@@spid,);
34 | commit
35 | go
36 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/17.Chapter 17 (Lock Types)/04.1.(X) Lock Behavior.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 17. Lock Types */
10 | /* (X) Lock Behavior (Session 1) */
11 | /****************************************************************************/
12 |
13 | use [SqlServerInternals]
14 | go
15 |
16 | /****************************************************************************/
17 | /* That script uses the objects created in "01.DB Creation.sql" script */
18 | /* from 00.Init project */
19 | /****************************************************************************/
20 |
21 | -- (X) lock behavior does not depend on transaction isolation level
22 | -- Notice that we are using READ UNCOMMITTED here
23 | set transaction isolation level read uncommitted
24 | begin tran
25 | delete from Delivery.Orders
26 | where OrderId = 95;
27 |
28 | -- Run Session 2 code
29 | rollback
30 | go
31 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/17.Chapter 17 (Lock Types)/04.2.(X) Lock Behavior.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 17. Lock Types */
10 | /* (X) Lock Behavior (Session 2) */
11 | /****************************************************************************/
12 |
13 | use [SqlServerInternals]
14 | go
15 |
16 | /****************************************************************************/
17 | /* That script uses the objects created in "01.DB Creation.sql" script */
18 | /* from 00.Init project */
19 | /****************************************************************************/
20 |
21 | -- No (S) locks in READ UNCOMMITTED
22 | select OrderId, Amount
23 | from Delivery.Orders with (nolock)
24 | where OrderId between 94 and 96;
25 | go
26 |
27 | -- No (S) locks in READ UNCOMMITTED
28 | set transaction isolation level read uncommitted
29 | select OrderId, Amount
30 | from Delivery.Orders
31 | where OrderId between 94 and 96;
32 | go
33 |
34 | -- (S) locks and blocking in READ COMMITTED
35 | -- It would work differently if READ_COMMITTED_SNAPSHOT database option is enabled
36 | set transaction isolation level read committed
37 | select OrderId, Amount
38 | from Delivery.Orders
39 | where OrderId between 94 and 96;
40 | go
41 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/17.Chapter 17 (Lock Types)/05.(S) Locks Behavior.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 17. Lock Types */
10 | /* Transaction Isolation Levels and Shared (S) Locks Behavior */
11 | /****************************************************************************/
12 |
13 | use [SqlServerInternals]
14 | go
15 |
16 | /****************************************************************************/
17 | /* That script uses the objects created in "01.DB Creation.sql" script */
18 | /* from 00.Init project */
19 | /****************************************************************************/
20 |
21 |
22 | --- Run SQL Profiler or Extended Events and monitor Lock Acquired/Lock
23 | --- Released events filtering by @@SPID.
24 |
25 | -- (S) Locks are released immediately after row was read
26 | set transaction isolation level read committed
27 | select OrderId, Amount
28 | from Delivery.Orders
29 | where OrderId between 94 and 96;
30 | go
31 |
32 | -- (S) Locks held till the end of transaction
33 | set transaction isolation level repeatable read
34 | select OrderId, Amount
35 | from Delivery.Orders
36 | where OrderId between 94 and 96;
37 | go
38 |
39 | -- Key Range (S) Locks held till the end of transaction
40 | set transaction isolation level serializable
41 | select OrderId, Amount
42 | from Delivery.Orders
43 | where OrderId between 94 and 96;
44 | go
45 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/18.Chapter 18 (Troubleshooting Blocking Issues)/01.1.Creating Blocking.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 18. Troubleshooting Blocking Issues */
10 | /* Create Blocking Condition (Session 1) */
11 | /****************************************************************************/
12 |
13 | use [SqlServerInternals]
14 | go
15 |
16 | /****************************************************************************/
17 | /* That script uses the objects created in "01.DB Creation.sql" script */
18 | /* from 00.Init project */
19 | /****************************************************************************/
20 |
21 | set transaction isolation level read uncommitted
22 | begin tran
23 | delete from Delivery.Orders
24 | where OrderId = 97;
25 |
26 | -- Run Session 2 code
27 | -- Do not Commit/Rollback transaction
28 | rollback
29 | go
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/18.Chapter 18 (Troubleshooting Blocking Issues)/01.2.Creating Blocking.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 18. Troubleshooting Blocking Issues */
10 | /* Create Blocking Condition (Session 2) */
11 | /****************************************************************************/
12 |
13 | use [SqlServerInternals]
14 | go
15 |
16 | /****************************************************************************/
17 | /* That script uses the objects created in "01.DB Creation.sql" script */
18 | /* from 00.Init project */
19 | /****************************************************************************/
20 |
21 | set transaction isolation level read committed
22 | select OrderId, Amount
23 | from Delivery.Orders
24 | where OrderNum = '950';
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/18.Chapter 18 (Troubleshooting Blocking Issues)/03.Set Blocked Process Threshold.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 18. Troubleshooting Blocking Issues */
10 | /* Setting Blocked Process Threshold */
11 | /****************************************************************************/
12 |
13 | sp_configure 'show advanced options', 1;
14 | go
15 | reconfigure;
16 | go
17 | sp_configure 'blocked process threshold', 20; -- In seconds.
18 | go
19 | reconfigure;
20 | go
21 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/18.Chapter 18 (Troubleshooting Blocking Issues)/04.Obtaining SQL and Plan by sql_handle.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 18. Troubleshooting Blocking Issues */
10 | /* Obtaining SQL Text and Execution Plan by sql_handle */
11 | /****************************************************************************/
12 |
13 | declare
14 | @H varbinary(max) =
15 | /* Insert sql_handle from the top line of the execution stack */
16 | ,@S int =
17 | /* Insert stmtStart from the top line of the execution stack */
18 | ,@E int =
19 | /* Insert stmtEnd from the top line of the execution stack */
20 |
21 | select
22 | substring(
23 | qt.text,
24 | (qs.statement_start_offset / 2) + 1,
25 | ((case qs.statement_end_offset
26 | when -1 then datalength(qt.text)
27 | else qs.statement_end_offset
28 | end - qs.statement_start_offset) / 2) + 1
29 | ) as sql
30 | ,qp.query_plan
31 | ,qs.creation_time
32 | ,qs.last_execution_time
33 | from
34 | sys.dm_exec_query_stats qs with (nolock)
35 | cross apply sys.dm_exec_sql_text(qs.sql_handle) qt
36 | cross apply sys.dm_exec_query_plan(qs.plan_handle) qp
37 | where
38 | qs.sql_handle = @H and
39 | qs.statement_start_offset = @S
40 | and qs.statement_end_offset = @E
41 | option (recompile);
42 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/18.Chapter 18 (Troubleshooting Blocking Issues)/05.Obtaining SQL and Plan from sys_dm_exec_requests.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 18. Troubleshooting Blocking Issues */
10 | /* Obtaining SQL Text and Execution Plan from sys.dm_exec_requests */
11 | /****************************************************************************/
12 |
13 | declare
14 | @SPID int =
15 |
16 | select
17 | er.session_id
18 | ,er.start_time
19 | ,er.status
20 | ,er.wait_type
21 | ,er.last_wait_type
22 | ,er.wait_time
23 | ,substring(
24 | qt.text,
25 | (er.statement_start_offset / 2) + 1,
26 | ((case er.statement_end_offset
27 | when -1 then datalength(qt.text)
28 | else er.statement_end_offset
29 | end - er.statement_start_offset) / 2) + 1
30 | ) as sql
31 | ,qp.query_plan
32 | from
33 | sys.dm_exec_requests er with (nolock)
34 | cross apply sys.dm_exec_sql_text(er.sql_handle) qt
35 | cross apply sys.dm_exec_query_plan(er.plan_handle) qp
36 | where
37 | er.session_id = @SPID
38 | option (recompile);
39 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/18.Chapter 18 (Troubleshooting Blocking Issues)/18.Chapter 18 (Troubleshooting Blocking Issues) (SQL Server 2005).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.1.Creating Blocking.sql
14 |
15 |
16 |
17 |
18 |
19 | 01.2.Creating Blocking.sql
20 |
21 |
22 |
23 |
24 |
25 | 02.DMVs.sql
26 |
27 |
28 |
29 |
30 |
31 | 03.Set Blocked Process Threshold.sql
32 |
33 |
34 |
35 |
36 |
37 | 04.Obtaining SQL and Plan by sql_handle.sql
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/19.Chapter 19 (Deadlocks)/01.1.Non-optimized Queries Deadlock.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 19. Deadlocks */
10 | /* Deadlock Due to Non-Optimized Queries (Session 2) */
11 | /****************************************************************************/
12 |
13 | use [SqlServerInternals]
14 | go
15 |
16 | /****************************************************************************/
17 | /* That script uses the objects created in "01.DB Creation.sql" script */
18 | /* from 00.Init project */
19 | /****************************************************************************/
20 |
21 | -- STEP 1
22 | set transaction isolation level read committed
23 |
24 | begin tran
25 | update Delivery.Orders
26 | set Amount = Amount * 1.1
27 | where OrderId = 9999;
28 |
29 | -- Run Session 2 code
30 |
31 | -- STEP 2
32 | select count(*) as [Cnt]
33 | from Delivery.Orders
34 | where CustomerId = 65;
35 | rollback
36 | go
37 |
38 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/19.Chapter 19 (Deadlocks)/01.2.Non-optimized Queries Deadlock.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 19. Deadlocks */
10 | /* Deadlock Due to Non-Optimized Queries (Session 2) */
11 | /****************************************************************************/
12 |
13 | use [SqlServerInternals]
14 | go
15 |
16 | /****************************************************************************/
17 | /* That script uses the objects created in "01.DB Creation.sql" script */
18 | /* from 00.Init project */
19 | /****************************************************************************/
20 |
21 |
22 | set transaction isolation level read committed
23 | begin tran
24 | update Delivery.Orders
25 | set Amount = Amount * 1.1
26 | where OrderId = 1;
27 |
28 | select count(*) as [Cnt]
29 | from Delivery.Orders
30 | where CustomerId = 317;
31 | -- Run Session 1 STEP 2 Code
32 | rollback
33 | go
34 |
35 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/19.Chapter 19 (Deadlocks)/01.3.Non-optimized Queries Deadlock.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 19. Deadlocks */
10 | /* Deadlock Due to Non-Optimized Queries (Monitoring Query) */
11 | /****************************************************************************/
12 |
13 | /*** Run at time when both sessions are blocked ***/
14 |
15 | select
16 | tl.request_session_id as [SPID]
17 | ,tl.resource_type as [Resouce Type]
18 | ,tl.resource_description as [Resource]
19 | ,tl.request_mode as [Mode]
20 | ,tl.request_status as [Status]
21 | ,wt.blocking_session_id as [Blocked By]
22 | from
23 | sys.dm_tran_locks tl with (nolock) left outer join sys.dm_os_waiting_tasks wt with (nolock) on
24 | tl.lock_owner_address = wt.resource_address and tl.request_status = 'WAIT'
25 | where
26 | tl.request_session_id <> @@SPID
27 | order by
28 | tl.request_session_id
29 | option (recompile);
30 |
31 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/19.Chapter 19 (Deadlocks)/02.2.Key Lookup Deadlock.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 19. Deadlocks */
10 | /* Key Lookup Deadlock (Session 2) */
11 | /****************************************************************************/
12 |
13 | set nocount on
14 | go
15 |
16 | use [SqlServerInternals]
17 | go
18 |
19 | -- Session 2 code (Run in parallel with Session 1 code)
20 | declare
21 | @Col int
22 |
23 | while 1 = 1
24 | begin
25 | select @Col = Col1
26 | from dbo.Data
27 | where NCIKey = 10;
28 | end
29 | go
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/19.Chapter 19 (Deadlocks)/03.2.Multiple Updates.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 19. Deadlocks */
10 | /* Deadlock Due to Multiple Updates (Session 2) */
11 | /****************************************************************************/
12 |
13 | set nocount on
14 | go
15 |
16 | use [SqlServerInternals]
17 | go
18 |
19 | select top 10 ID, Value, ModTime
20 | from dbo.Data
21 | where ModTime > '2001-01-01'
22 | order by ModTime, ID;
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/20.Chapter 20 (Lock Escalations)/01.2 Lock Escalation and Concurrency.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 20. Lock Escalations */
10 | /* Disabled Lock Escalation and Concurrency (Session 2) */
11 | /****************************************************************************/
12 |
13 | use [SqlServerInternals]
14 | go
15 |
16 | /****************************************************************************/
17 | /* That script uses the objects created in "01.DB Creation.sql" script */
18 | /* from 00.Init project */
19 | /****************************************************************************/
20 |
21 | insert into Delivery.Orders(OrderDate,OrderNum, CustomerId, PickupAddressId
22 | ,DeliveryAddressId, ServiceId, RatePlanId, OrderStatusId, Pieces, Amount)
23 | values('2016-06-01T08:00:00', '123456', 1, 1, 3, 1, 1, 1, 2, 25);
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/20.Chapter 20 (Lock Escalations)/02.Multiple Statements.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 20. Lock Escalations */
10 | /* Multiple Statements and Lock Escalations */
11 | /****************************************************************************/
12 |
13 | use [SqlServerInternals]
14 | go
15 |
16 | /****************************************************************************/
17 | /* That script uses the objects created in "01.DB Creation.sql" script */
18 | /* from 00.Init project */
19 | /****************************************************************************/
20 |
21 | declare
22 | @I int
23 |
24 | select @I = 0;
25 |
26 | begin tran
27 | while @I < 65000
28 | begin
29 | update Delivery.Orders
30 | set OrderStatusId = 1
31 | where OrderId between @I and @I + 4900;
32 |
33 | select @I = @I + 4900;
34 | end
35 |
36 | select count(*) as [Lock Count]
37 | from sys.dm_tran_locks
38 | where request_session_id = @@SPID;
39 | rollback
40 | go
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/20.Chapter 20 (Lock Escalations)/20.Chapter 20 (Lock Escalations).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.1.Lock Escalation and Concurrency.sql
14 |
15 |
16 |
17 |
18 |
19 | 01.2 Lock Escalation and Concurrency.sql
20 |
21 |
22 |
23 |
24 |
25 | 02.Multiple Statements.sql
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/21.Chapter 21 (Optimistic Isolation Levels)/01.1.RCSI.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 21. Optimistic Isolation Levels */
10 | /* Read Committed Snapshot Isolation (Session 1) */
11 | /****************************************************************************/
12 |
13 |
14 | /****************************************************************************/
15 | /* Do not forget to disable RCSI isolation after script execution */
16 | /* (Code is at the end of the script) */
17 | /****************************************************************************/
18 |
19 |
20 | use [SqlServerInternals]
21 | go
22 |
23 | /****************************************************************************/
24 | /* That script uses the objects created in "01.DB Creation.sql" script */
25 | /* from 00.Init project */
26 | /****************************************************************************/
27 |
28 | /*** Enabling RCSI ***/
29 | alter database SqlServerInternals
30 | set read_committed_snapshot on
31 | with rollback after 3 seconds;
32 | go
33 |
34 |
35 | -- Step 1:
36 | begin tran
37 | update Delivery.Orders
38 | set Reference = 'Updated in Session 1'
39 | where OrderId = 1;
40 |
41 | -- Run code from Session 2 script
42 | rollback
43 | go
44 |
45 | /*** Disabling RCSI ***/
46 | alter database SqlServerInternals
47 | set read_committed_snapshot off
48 | with rollback after 3 seconds;
49 | go
50 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/21.Chapter 21 (Optimistic Isolation Levels)/01.2.RCSI.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 21. Optimistic Isolation Levels */
10 | /* Read Committed Snapshot Isolation (Session 2) */
11 | /****************************************************************************/
12 |
13 |
14 | use [SqlServerInternals]
15 | go
16 |
17 | /****************************************************************************/
18 | /* That script uses the objects created in "01.DB Creation.sql" script */
19 | /* from 00.Init project */
20 | /****************************************************************************/
21 |
22 | /*** Test 1: RCSI and Readers ***/
23 | -- Session reads old version of the row
24 | select * from Delivery.Orders where OrderId = 1;
25 | go
26 |
27 | /*** Test 2 RCSI and Writers (X) locks ***/
28 | -- (X) lock is blocked
29 | begin tran
30 | update Delivery.Orders
31 | set Reference = 'Updated in Session 2'
32 | where OrderId = 1;
33 | rollback
34 | go
35 |
36 | /*** Test 3 RCSI and Writers (U) locks ***/
37 | -- (U) lock is blocked
38 | -- Step 1:
39 | begin tran
40 | update Delivery.Orders
41 | set Reference = 'Updated in Session 2'
42 | where OrderNum = '23';
43 | rollback
44 | go
45 |
46 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/21.Chapter 21 (Optimistic Isolation Levels)/02.1.Snapshot.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 21. Optimistic Isolation Levels */
10 | /* Snapshot Isolation (Session 1) */
11 | /****************************************************************************/
12 |
13 | use [SqlServerInternals]
14 | go
15 |
16 | /****************************************************************************/
17 | /* That script uses the objects created in "01.DB Creation.sql" script */
18 | /* from 00.Init project */
19 | /****************************************************************************/
20 |
21 | /*** Enabling Snapshot ***/
22 | alter database SqlServerInternals
23 | set allow_snapshot_isolation on;
24 | go
25 |
26 |
27 | -- Step 1:
28 | -- Isolation level does not affect behavior
29 | begin tran
30 | update Delivery.Orders
31 | set Reference = 'Updated in Session 1'
32 | where OrderId = 1;
33 |
34 | -- Run code from Session 2 script
35 | rollback
36 | go
37 |
38 | /*** Enabling Snapshot ***/
39 | alter database SqlServerInternals
40 | set allow_snapshot_isolation off;
41 | go
42 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/21.Chapter 21 (Optimistic Isolation Levels)/03.1.Error 3960.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 21. Optimistic Isolation Levels */
10 | /* Snapshot Isolation and Error 3960 (Session 1) */
11 | /****************************************************************************/
12 |
13 | use [SqlServerInternals]
14 | go
15 |
16 | /****************************************************************************/
17 | /* That script uses the objects created in "01.DB Creation.sql" script */
18 | /* from 00.Init project */
19 | /****************************************************************************/
20 |
21 | /*** Enabling snapshot ***/
22 | alter database SqlServerInternals
23 | set allow_snapshot_isolation on;
24 | go
25 |
26 |
27 | -- Step 1 -- starting transaction
28 | set transaction isolation level snapshot
29 | begin tran
30 | select *
31 | from Delivery.Orders
32 | where OrderId = 1000;
33 |
34 | -- Run Session 2 code
35 |
36 | -- Step 2
37 | update Delivery.Orders
38 | set Reference = convert(varchar(48),newid())
39 | where OrderId = 1;
40 | commit
41 | go
42 |
43 |
44 | /*** Disabling Snapshot ***/
45 | alter database SqlServerInternals
46 | set allow_snapshot_isolation off;
47 | go
48 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/21.Chapter 21 (Optimistic Isolation Levels)/03.2.Error 3960.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 21. Optimistic Isolation Levels */
10 | /* Snapshot Isolation and Error 3960 (Session 2) */
11 | /****************************************************************************/
12 |
13 | use [SqlServerInternals]
14 | go
15 |
16 | /****************************************************************************/
17 | /* That script uses the objects created in "01.DB Creation.sql" script */
18 | /* from 00.Init project */
19 | /****************************************************************************/
20 |
21 | update Delivery.Orders
22 | set Reference = convert(varchar(48),newid())
23 | where OrderId = 1;
24 | go
25 |
26 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/21.Chapter 21 (Optimistic Isolation Levels)/04.2.Optimistic vs Pessimistic Locking.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 21. Optimistic Isolation Levels */
10 | /* Optimistic vs. Pessimistic Locking (Session 2) */
11 | /****************************************************************************/
12 |
13 | set nocount on
14 | go
15 |
16 | use [SqlServerInternals]
17 | go
18 |
19 | /*** Test 1: Pessimistic Locking ***/
20 | -- Session would be blocked until 1st session commits
21 | set transaction isolation level read committed
22 | begin tran
23 | update dbo.Colors
24 | set Color = 'Black'
25 | where Color = 'White';
26 | commit
27 | go
28 |
29 |
30 |
31 | /*** Test 2: Optimistic Locking ***/
32 |
33 | -- Step 1 -- starting transaction
34 | set transaction isolation level snapshot
35 | begin tran
36 | update dbo.Colors
37 | set Color = 'Black'
38 | where Color = 'White';
39 | commit
40 | go
41 |
42 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/22.Chapter 22 (Application Locks)/01.Table Creation.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 22. Application Locks */
10 | /* Table Creation */
11 | /****************************************************************************/
12 |
13 | set nocount on
14 | go
15 |
16 | use [SqlServerInternals]
17 | go
18 |
19 | if exists(select * from sys.tables t join sys.schemas s on t.schema_id = s.schema_id where s.name = 'dbo' and t.name = 'RawData') drop table dbo.RawData;
20 | go
21 |
22 | create table dbo.RawData
23 | (
24 | ID int not null,
25 | Attributes char(100) not null
26 | constraint DEF_RawData_Attributes
27 | default 'Other columns',
28 | ProcessingTime datetime not null
29 | constraint DEF_RawData_ProcessingTime
30 | default '2010-01-01',
31 |
32 | constraint PK_RawData
33 | primary key clustered(ID)
34 | );
35 | go
36 |
37 |
38 | ;with N1(C) as (select 0 union all select 0) -- 2 rows
39 | ,N2(C) as (select 0 from N1 as T1 cross join N1 as T2) -- 4 rows
40 | ,N3(C) as (select 0 from N2 as T1 cross join N2 as T2) -- 16 rows
41 | ,N4(C) as (select 0 from N3 as T1 cross join N3 as T2) -- 256 rows
42 | ,IDs(ID) as (select ROW_NUMBER() over (order by (select NULL)) from N4)
43 | insert into dbo.RawData(ID)
44 | select ID
45 | from IDs;
46 | go
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/22.Chapter 22 (Application Locks)/02.2.Application Locks.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 22. Application Locks */
10 | /* Application Locks (Session 2) */
11 | /****************************************************************************/
12 |
13 | set noexec off
14 | go
15 |
16 | set nocount on
17 | go
18 |
19 | use [SqlServerInternals]
20 | go
21 |
22 | if not exists
23 | (
24 | select *
25 | from sys.tables t join sys.schemas s on
26 | t.schema_id = s.schema_id
27 | where
28 | s.name = 'dbo' and t.name = 'RawData'
29 | )
30 | begin
31 | raiserror('Please create [RawData] table with "01.Table Creation.sql" script',16,1) with nowait;
32 | set noexec on
33 | end
34 | go
35 |
36 | -- Session 2 code
37 | exec dbo.LoadRawData @PacketSize = 50;
38 | go
39 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/22.Chapter 22 (Application Locks)/03.1.Workaround With Locking Hints.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 22. Application Locks */
10 | /* Workaround with Locking Hints (Session 1) */
11 | /****************************************************************************/
12 |
13 | set noexec off
14 | go
15 |
16 | set nocount on
17 | go
18 |
19 | use [SqlServerInternals]
20 | go
21 |
22 | if not exists
23 | (
24 | select *
25 | from sys.tables t join sys.schemas s on
26 | t.schema_id = s.schema_id
27 | where
28 | s.name = 'dbo' and t.name = 'RawData'
29 | )
30 | begin
31 | raiserror('Please create [RawData] table with "01.Table Creation.sql" script',16,1) with nowait;
32 | set noexec on
33 | end
34 | go
35 |
36 | -- Session 1 code
37 | -- Using transaction and waitfor delay to emulate concurrent activity
38 |
39 | -- STEP 1
40 | declare
41 | @EarliestProcessingTime datetime
42 | select @EarliestProcessingTime = dateadd(minute,-1,getutcdate())
43 |
44 | begin tran
45 | ;with DataPacket(ID, Attributes, ProcessingTime)
46 | as
47 | (
48 | select top (50) ID, Attributes, ProcessingTime
49 | from dbo.RawData with (updlock, readpast)
50 | where ProcessingTime <= @EarliestProcessingTime
51 | order by ID
52 | )
53 | update DataPacket
54 | set ProcessingTime = getutcdate()
55 | output inserted.ID, inserted.Attributes;
56 |
57 | -- Run Session 2 code. All Exclusive locks are held now
58 | commit
59 | go
60 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/22.Chapter 22 (Application Locks)/03.2.Workaround With Locking Hints.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 22. Application Locks */
10 | /* Workaround with Locking Hints (Session 2) */
11 | /****************************************************************************/
12 |
13 | set noexec off
14 | go
15 |
16 | set nocount on
17 | go
18 |
19 | use [SqlServerInternals]
20 | go
21 |
22 | if not exists
23 | (
24 | select *
25 | from sys.tables t join sys.schemas s on
26 | t.schema_id = s.schema_id
27 | where
28 | s.name = 'dbo' and t.name = 'RawData'
29 | )
30 | begin
31 | raiserror('Please create [RawData] table with "01.Table Creation.sql" script',16,1) with nowait;
32 | set noexec on
33 | end
34 | go
35 |
36 | -- Session 2 code
37 | declare
38 | @EarliestProcessingTime datetime
39 | select @EarliestProcessingTime = dateadd(minute,-1,getutcdate())
40 |
41 | begin tran
42 | ;with DataPacket(ID, Attributes, ProcessingTime)
43 | as
44 | (
45 | select top (50) ID, Attributes, ProcessingTime
46 | from dbo.RawData with (updlock, readpast)
47 | where ProcessingTime <= @EarliestProcessingTime
48 | order by ID
49 | )
50 | update DataPacket
51 | set ProcessingTime = getutcdate()
52 | output inserted.ID, inserted.Attributes ;
53 | commit
54 | go
55 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/22.Chapter 22 (Application Locks)/22.Chapter 22 (Application Locks).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.Table Creation.sql
14 |
15 |
16 |
17 |
18 |
19 | 02.1.Application Locks.sql
20 |
21 |
22 |
23 |
24 |
25 | 02.2.Application Locks.sql
26 |
27 |
28 |
29 |
30 |
31 | 03.1.Workaround With Locking Hints.sql
32 |
33 |
34 |
35 |
36 |
37 | 03.2.Workaround With Locking Hints.sql
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/23.Chapter 23 (Schema Locks)/01.1.Schema Locks.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 23. Schema Locks */
10 | /* Schema Lock Demo (Session 1) */
11 | /****************************************************************************/
12 |
13 | use [SqlServerInternals]
14 | go
15 |
16 | /****************************************************************************/
17 | /* That script uses the objects created in "01.DB Creation.sql" script */
18 | /* from 00.Init project */
19 | /****************************************************************************/
20 |
21 | /*** This script clears content of plan cache. Do not run on production server ***/
22 | dbcc freeproccache
23 | go
24 |
25 | -- Run steps below 2 times. First time, sessions 2 and 3 will wait for
26 | -- schema-stability (Sch-S) locks. Second time (plans are cached), session 3
27 | -- would wait for intent exclusive (IX) lock
28 |
29 | -- STEP 1
30 | begin tran
31 | alter table Delivery.Orders add Dummy int;
32 |
33 | -- Run Session 2 and Session 3 code
34 |
35 | select
36 | resource_type
37 | ,request_type
38 | ,request_mode
39 | ,request_status
40 | from sys.dm_tran_locks
41 | where
42 | resource_associated_entity_id =
43 | object_id(N'Delivery.Orders');
44 | rollback
45 | go
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/23.Chapter 23 (Schema Locks)/01.2.Schema Locks.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 23. Schema Locks */
10 | /* Schema Lock Demo (Session 2) */
11 | /****************************************************************************/
12 |
13 | use [SqlServerInternals]
14 | go
15 |
16 | /****************************************************************************/
17 | /* That script uses the objects created in "01.DB Creation.sql" script */
18 | /* from 00.Init project */
19 | /****************************************************************************/
20 |
21 | select count(*)
22 | from Delivery.Orders with (nolock);
23 | go
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/23.Chapter 23 (Schema Locks)/01.3.Schema Locks.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 23. Schema Locks */
10 | /* Schema Lock Demo (Session 3) */
11 | /****************************************************************************/
12 |
13 | use [SqlServerInternals]
14 | go
15 |
16 | /****************************************************************************/
17 | /* That script uses the objects created in "01.DB Creation.sql" script */
18 | /* from 00.Init project */
19 | /****************************************************************************/
20 |
21 | begin tran
22 | delete
23 | from Delivery.Orders
24 | where OrderId = 1;
25 | rollback
26 | go
27 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/23.Chapter 23 (Schema Locks)/02.1.Lock Compatibility.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 23. Schema Locks */
10 | /* Lock Compatibility (Session 1) */
11 | /****************************************************************************/
12 |
13 | use [SqlServerInternals]
14 | go
15 |
16 | /****************************************************************************/
17 | /* That script uses the objects created in "01.DB Creation.sql" script */
18 | /* from 00.Init project */
19 | /****************************************************************************/
20 |
21 | -- STEP 1:
22 | begin tran
23 | select *
24 | from Delivery.Orders
25 | with (repeatableread)
26 | where OrderId = 1;
27 |
28 | -- Run Sessions 2 and 3 code
29 |
30 | -- STEP 2:
31 | select
32 | l.request_session_id as [SPID]
33 | ,l.resource_description
34 | ,l.resource_type
35 | ,l.request_mode
36 | ,l.request_status
37 | ,r.blocking_session_id
38 | from
39 | sys.dm_tran_locks l join
40 | sys.dm_exec_requests r on
41 | l.request_session_id =
42 | r.session_id
43 | where
44 | resource_type = 'KEY';
45 | rollback
46 | go
47 |
48 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/23.Chapter 23 (Schema Locks)/02.2.Lock Compatibility.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 23. Schema Locks */
10 | /* Lock Compatibility (Session 2) */
11 | /****************************************************************************/
12 |
13 | use [SqlServerInternals]
14 | go
15 |
16 | /****************************************************************************/
17 | /* That script uses the objects created in "01.DB Creation.sql" script */
18 | /* from 00.Init project */
19 | /****************************************************************************/
20 |
21 | begin tran
22 | delete
23 | from Delivery.Orders
24 | where OrderId = 1;
25 | rollback
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/23.Chapter 23 (Schema Locks)/02.3.Lock Compatibility.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 23. Schema Locks */
10 | /* Lock Compatibility (Session 3) */
11 | /****************************************************************************/
12 |
13 | use [SqlServerInternals]
14 | go
15 |
16 | /****************************************************************************/
17 | /* That script uses the objects created in "01.DB Creation.sql" script */
18 | /* from 00.Init project */
19 | /****************************************************************************/
20 |
21 | -- TEST 1: using READ COMMITTED
22 | -- It may or may not be blocked.
23 | select *
24 | from Delivery.Orders with (readcommitted)
25 | where OrderId = 1;
26 | go
27 |
28 | -- TEST 2: using REPEATABLE READ
29 | -- It will be blocked
30 | select *
31 | from Delivery.Orders with (readcommitted)
32 | where OrderId = 1;
33 | go
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/23.Chapter 23 (Schema Locks)/03.3.Low Priority Locks.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 23. Schema Locks */
10 | /* Low Priority Locks (Session 3) */
11 | /****************************************************************************/
12 |
13 | set noexec off
14 | go
15 |
16 | set nocount on
17 | go
18 |
19 | use [SqlServerInternals]
20 | go
21 |
22 | if convert(int,
23 | left(
24 | convert(nvarchar(128), serverproperty('ProductVersion')),
25 | charindex('.',convert(nvarchar(128), serverproperty('ProductVersion'))) - 1
26 | )
27 | ) < 12
28 | begin
29 | raiserror('You should have SQL Server 2014-2016 to execute this script',16,1) with nowait;
30 | set noexec on
31 | end
32 | go
33 |
34 | if convert(int, serverproperty('EngineEdition')) != 3
35 | begin
36 | raiserror('That script requires Enterprise Edition of SQL Server to run',16,1);
37 | set noexec on
38 | end
39 | go
40 |
41 | use [SqlServerInternals]
42 | go
43 |
44 | -- Session would be blocked when Index Rebuild uses regular locks and
45 | -- would not be blocked with low priority locks
46 | select *
47 | from dbo.Data with (nolock)
48 | where Id = 2;
49 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/25.Chapter 25 (Query Optimization and Execution)/25.Chapter 25 (Query Optimization and Execution).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.Removing Contradictions.sql
14 |
15 |
16 |
17 |
18 |
19 | 02.Variable-length Cols and Memory Grants.sql
20 |
21 |
22 |
23 |
24 |
25 | 03.Spools.sql
26 |
27 |
28 |
29 |
30 |
31 | 04.Halloween Protection.sql
32 |
33 |
34 |
35 |
36 |
37 | 05.Parallelism.sql
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/26.Chapter 26 (Plan Caching)/26.Chapter 26 (Plan Caching) (SQL Server 2005).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.Parameter Sniffing.sql
14 |
15 |
16 |
17 |
18 |
19 | 02.Plan Reuse.sql
20 |
21 |
22 |
23 |
24 |
25 | 06.Examining Plan Cache.sql
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/28.Chapter 28 (System Troubleshooting)/04.Buffer Pool Usage.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 28. System Troubleshooting */
10 | /* Buffer Pool Usage */
11 | /****************************************************************************/
12 |
13 | /*** Buffer Pool Usage on Per-Database Basis ***/
14 | select
15 | database_id as [DB ID]
16 | ,db_name(database_id) as [DB Name]
17 | ,convert(decimal(11,3),count(*) * 8 / 1024.0) as
18 | [Buffer Pool Size (MB)]
19 | from sys.dm_os_buffer_descriptors with (nolock)
20 | group by database_id
21 | order by [Buffer Pool Size (MB)] desc
22 | option (recompile);
23 | go
24 |
25 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/28.Chapter 28 (System Troubleshooting)/06.Enable Remote DAC.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 28. System Troubleshooting */
10 | /* Enable Remote DAC Connection */
11 | /****************************************************************************/
12 |
13 | exec sp_configure 'remote admin connections', 1 ;
14 | go
15 | reconfigure;
16 | go
17 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/28.Chapter 28 (System Troubleshooting)/08.Latch Stats.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 28. System Troubleshooting */
10 | /* Latch Statistics */
11 | /****************************************************************************/
12 |
13 |
14 | /*** Clearing Waits ***/
15 | -- DBCC SQLPERF('sys.dm_os_latch_stats', CLEAR);
16 |
17 | ;with Latches
18 | as
19 | (
20 | select latch_class, wait_time_ms, waiting_requests_count
21 | ,100. * wait_time_ms / SUM(wait_time_ms) over() as Pct
22 | ,row_number() over(order by wait_time_ms desc) AS RowNum
23 | from sys.dm_os_latch_stats with (nolock)
24 | where latch_class not in (N'BUFFER',N'SLEEP_TASK') and wait_time_ms > 0
25 | )
26 | select
27 | l1.latch_class as [Latch Type]
28 | ,l1.waiting_requests_count as [Wait Count]
29 | ,convert(decimal(12,3), l1.wait_time_ms / 1000.0) as [Wait Time]
30 | ,convert(decimal(12,1), l1.wait_time_ms /
31 | l1.waiting_requests_count) as [Avg Wait Time]
32 | ,convert(decimal(6,3), l1.Pct) as [Percent]
33 | ,convert(decimal(6,3), l2.Pct) as [Running Percent]
34 | from
35 | Latches l1 cross apply
36 | (
37 | select sum(l2.Pct) as Pct
38 | from Latches l2
39 | where l2.RowNum <= l1.RowNum
40 | ) l2
41 | where
42 | l1.RowNum = 1 or l2.Pct < 99
43 | option (recompile);
44 | go
45 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/29.Chapter 29 (Query Store)/02.2.Emulating Parameter Sniffing.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 29. Query Store */
10 | /* Emulating Parameter Sniffing (Session 2) */
11 | /****************************************************************************/
12 |
13 | set noexec off
14 | go
15 |
16 | if convert(int,
17 | left(
18 | convert(nvarchar(128), serverproperty('ProductVersion')),
19 | charindex('.',convert(nvarchar(128), serverproperty('ProductVersion'))) - 1
20 | )
21 | ) < 13
22 | begin
23 | raiserror('You should have SQL Server 2016 to execute this script',16,1) with nowait
24 | set noexec on
25 | end
26 | go
27 |
28 | use SQLServerInternals
29 | go
30 |
31 | if not exists
32 | (
33 | select *
34 | from sys.procedures p join sys.schemas s on p.schema_id = s.schema_id
35 | where s.name = 'dbo' and p.name = 'GetAverageSalary'
36 | )
37 |
38 | begin
39 | raiserror('Please create the objects and run dbo.GetAverageSalary SP from "02.1.Emulating Parameter Sniffing.sql" script',16,1) with nowait
40 | set noexec on
41 | end
42 | go
43 |
44 | -- Clearing procedure plan cache for the database
45 | alter database scoped configuration clear procedure_cache;
46 | go
47 |
48 | exec dbo.GetAverageSalary @Country='CANADA';
49 | go
50 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/29.Chapter 29 (Query Store)/05.Disable Query Store (Cleanup).sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 29. Query Store */
10 | /* Disable Query Store (Clean-Up) */
11 | /****************************************************************************/
12 |
13 | set noexec off
14 | go
15 |
16 | if convert(int,
17 | left(
18 | convert(nvarchar(128), serverproperty('ProductVersion')),
19 | charindex('.',convert(nvarchar(128), serverproperty('ProductVersion'))) - 1
20 | )
21 | ) < 13
22 | begin
23 | raiserror('You should have SQL Server 2016 to execute this script',16,1) with nowait;
24 | set noexec on
25 | end
26 | go
27 |
28 | use master
29 | go
30 |
31 | alter database SQLServerInternals set query_store clear;
32 | alter database SQLServerInternals set query_store = off;
33 | go
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/30.Chapter 30 (Transaction Log Internals)/30.Chapter 30 (Transaction Log Internals).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.Troubleshooting Log Growth.sql
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/33.Chapter 33 (Column-Based Storage and Batch Mode Execution)/33.Chapter 33 (Column-Based Storage and Batch Mode Execution).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.Batch Mode Execution.sql
14 |
15 |
16 |
17 |
18 |
19 | 02.Columnstore Index Metadata.sql
20 |
21 |
22 |
23 |
24 |
25 | 03.String Columns in Predicates.sql
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/34.Chapter 34 (Columnstore Indexes)/34.Chapter 34 (Columnstore Indexes) (SQL Server 2012).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.Switching Partition.sql
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/34.Chapter 34 (Columnstore Indexes)/34.Chapter 34 (Columnstore Indexes) (SQL Server 2014).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.Switching Partition.sql
14 |
15 |
16 |
17 |
18 |
19 | 02.Delta Store and Delete Bitmap.sql
20 |
21 |
22 |
23 |
24 |
25 | 03.Delta Store Data Compression.sql
26 |
27 |
28 |
29 |
30 |
31 | 04.Delete Bitmap Compression.sql
32 |
33 |
34 |
35 |
36 |
37 | 07.DMVs (2014).sql
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/35.Chapter 35 (In-Memory OLTP Internals)/05.Memory Usage.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 35. In-Memory OLTP Internals */
10 | /* Memory-Optimized Tables Memory Usage */
11 | /****************************************************************************/
12 |
13 | set noexec off
14 | go
15 |
16 | if convert(int,
17 | left(
18 | convert(nvarchar(128), serverproperty('ProductVersion')),
19 | charindex('.',convert(nvarchar(128), serverproperty('ProductVersion'))) - 1
20 | )
21 | ) < 12
22 | begin
23 | raiserror('You should have SQL Server 2014-2016 to execute this script',16,1) with nowait;
24 | set noexec on
25 | end
26 | go
27 |
28 | if convert(int, serverproperty('EngineEdition')) != 3 or charindex('X64',@@Version) = 0
29 | begin
30 | raiserror('That script requires 64-Bit Enterprise Edition of SQL Server to run',16,1);
31 | set noexec on
32 | end
33 | go
34 |
35 | use SQLServerInternalsHK
36 | go
37 |
38 | select object_name(object_id) as [Object Name], *
39 | from sys.dm_db_xtp_table_memory_stats;
40 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/35.Chapter 35 (In-Memory OLTP Internals)/35.Chapter 35 (In-Memory OLTP Internals) (SQL Server 2014).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.Composite Hash Index.sql
14 |
15 |
16 |
17 |
18 |
19 | 02.Memory Consumers (SQL Server 2014).sql
20 |
21 |
22 |
23 |
24 |
25 | 05.Memory Usage.sql
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/35.Chapter 35 (In-Memory OLTP Internals)/35.Chapter 35 (In-Memory OLTP Internals) (SQL Server 2016).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.Composite Hash Index.sql
14 |
15 |
16 |
17 |
18 |
19 | 02.Memory Consumers.sql
20 |
21 |
22 |
23 |
24 |
25 | 03.Memory Consumers and Off-Row Storage.sql
26 |
27 |
28 |
29 |
30 |
31 | 04.Columnstore Indexes.sql
32 |
33 |
34 |
35 |
36 |
37 | 05.Memory Usage.sql
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/36.Chapter 36 (Transaction Processing in In-Memory OLTP)/07.2.Ref Integrity.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 36. Transaction Processing in In-Memory OLTP */
10 | /* Referential Integrity Enforcement (Session 2) */
11 | /****************************************************************************/
12 |
13 | set noexec off
14 | go
15 |
16 | if convert(int,
17 | left(
18 | convert(nvarchar(128), serverproperty('ProductVersion')),
19 | charindex('.',convert(nvarchar(128), serverproperty('ProductVersion'))) - 1
20 | )
21 | ) < 13
22 | begin
23 | raiserror('You should have SQL Server 2016 to execute this script',16,1) with nowait
24 | set noexec on
25 | end
26 | go
27 |
28 | if convert(int, serverproperty('EngineEdition')) != 3 or charindex('X64',@@Version) = 0
29 | begin
30 | raiserror('That script requires 64-Bit Enterprise Edition of SQL Server to run',16,1)
31 | set noexec on
32 | end
33 | go
34 |
35 | if not exists (select * from sys.databases where name = 'SQLServerInternalsHK')
36 | begin
37 | raiserror('Create [SQLServerInternalsHK] database with "02.Create In-Memory OLTP DB.sql" script from "00.Init" project',16,1)
38 | set noexec on
39 | end
40 | go
41 |
42 | use SQLServerInternalsHK
43 | go
44 |
45 | --Session 2 code
46 | update dbo.Transactions with (snapshot)
47 | set Amount = 30
48 | where TransactionId = 2;
49 |
50 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/37.Chapter 37 (In-Memory OLTP Programmability)/01.Loaded Objects.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 37. In-Memory OLTP Programmability */
10 | /* Natively-Compiled Objects Loaded Into Memory */
11 | /****************************************************************************/
12 |
13 | set noexec off
14 | go
15 |
16 | if convert(int,
17 | left(
18 | convert(nvarchar(128), serverproperty('ProductVersion')),
19 | charindex('.',convert(nvarchar(128), serverproperty('ProductVersion'))) - 1
20 | )
21 | ) < 12
22 | begin
23 | raiserror('You should have SQL Server 2014 to execute this script',16,1) with nowait;
24 | set noexec on
25 | end
26 | go
27 |
28 | if convert(int, serverproperty('EngineEdition')) != 3 or charindex('X64',@@Version) = 0
29 | begin
30 | raiserror('That script requires 64-Bit Enterprise Edition of SQL Server to run',16,1);
31 | set noexec on
32 | end
33 | go
34 |
35 | select
36 | s.name + '.' + o.name as [Object Name]
37 | ,o.object_id
38 | from
39 | (
40 | select schema_id, name, object_id
41 | from sys.tables
42 | where is_memory_optimized = 1
43 | union all
44 | select schema_id, name, object_id
45 | from sys.procedures
46 | ) o join sys.schemas s on
47 | o.schema_id = s.schema_id;
48 |
49 | select *
50 | from sys.dm_os_loaded_modules
51 | where description = 'XTP Native DLL';
52 | go
53 |
54 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/37.Chapter 37 (In-Memory OLTP Programmability)/02.2.Atomic Blocks.sql:
--------------------------------------------------------------------------------
1 | /****************************************************************************/
2 | /* Pro SQL Server Internals */
3 | /* APress. 2nd Edition. ISBN-13: 978-1484219638 ISBN-10:1484219635 */
4 | /* */
5 | /* Written by Dmitri V. Korotkevitch */
6 | /* http://aboutsqlserver.com */
7 | /* dk@aboutsqlserver.com */
8 | /****************************************************************************/
9 | /* Chapter 37. In-Memory OLTP Programmability */
10 | /* Atomic Blocks (Session 2) */
11 | /****************************************************************************/
12 |
13 | set noexec off
14 | go
15 |
16 | if convert(int,
17 | left(
18 | convert(nvarchar(128), serverproperty('ProductVersion')),
19 | charindex('.',convert(nvarchar(128), serverproperty('ProductVersion'))) - 1
20 | )
21 | ) < 12
22 | begin
23 | raiserror('You should have SQL Server 2014-2016 to execute this script',16,1) with nowait;
24 | set noexec on
25 | end
26 | go
27 |
28 | if convert(int, serverproperty('EngineEdition')) != 3 or charindex('X64',@@Version) = 0
29 | begin
30 | raiserror('That script requires 64-Bit Enterprise Edition of SQL Server to run',16,1);
31 | set noexec on
32 | end
33 | go
34 |
35 | if not exists (select * from sys.databases where name = 'SQLServerInternalsHK')
36 | begin
37 | raiserror('Create [SQLServerInternalsHK] database with "02.Create In-Memory OLTP DB.sql" script from "00.Init" project',16,1);
38 | set noexec on
39 | end
40 | go
41 |
42 | use SQLServerInternalsHK
43 | go
44 |
45 |
46 | /*** Session 2 Code: Triggering Write/Write conflict ***/
47 | begin tran
48 | -- Triggers an exception
49 | exec dbo.AtomicBlockDemo 1, -1, null, null;
50 |
51 | select @@TRANCOUNT as [@@TRANCOUNT], XACT_STATE() as [XACT_STATE()];
52 | --commit
53 | go
54 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/37.Chapter 37 (In-Memory OLTP Programmability)/37.Chapter 37 (In-Memory OLTP Programmability) (SQL Server 2014).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.Loaded Objects.sql
14 |
15 |
16 |
17 |
18 |
19 | 02.1.Atomic Blocks.sql
20 |
21 |
22 |
23 |
24 |
25 | 02.2.Atomic Blocks.sql
26 |
27 |
28 |
29 |
30 |
31 | 04.Execution Statistics.sql
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/37.Chapter 37 (In-Memory OLTP Programmability)/37.Chapter 37 (In-Memory OLTP Programmability) (SQL Server 2016).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.Loaded Objects.sql
14 |
15 |
16 |
17 |
18 |
19 | 02.1.Atomic Blocks.sql
20 |
21 |
22 |
23 |
24 |
25 | 02.2.Atomic Blocks.sql
26 |
27 |
28 |
29 |
30 |
31 | 03.Natively-compiled functions.sql
32 |
33 |
34 |
35 |
36 |
37 | 04.Execution Statistics.sql
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/SQL Server Internals 2nd Edition/SQL/99.Chapter 99 (System Design Considerations)/99.Chapter 99 (System Design Considerations).ssmssqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | 01.Implicit Data Type Conversion.sql
14 |
15 |
16 |
17 |
18 |
19 | 02.EF6 Analysis.sql
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/contributing.md:
--------------------------------------------------------------------------------
1 | # Contributing to Apress Source Code
2 |
3 | Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers.
4 |
5 | ## How to Contribute
6 |
7 | 1. Make sure you have a GitHub account.
8 | 2. Fork the repository for the relevant book.
9 | 3. Create a new branch on which to make your change, e.g.
10 | `git checkout -b my_code_contribution`
11 | 4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted.
12 | 5. Submit a pull request.
13 |
14 | Thank you for your contribution!
--------------------------------------------------------------------------------