This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use testing; | |
| go | |
| create type MyStringType from varchar(256); | |
| go | |
| create table TestMyString | |
| ( | |
| ThisIsMyString MyStringType not null | |
| ); | |
| go | |
| sp_help TestMyString |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Import-Module dbatools; | |
| $SqlInstance = 'localhost\sql17'; | |
| $MyDB = 'SequenceTesting'; | |
| $TableTime = Measure-Command { | |
| (1..100) | foreach-object -parallel { | |
| Invoke-DbaQuery -SqlInstance $sqlinstance -query "declare @newid int; exec GetNextNumberTable @newid" -Database $MyDB -As SingleValue | Out-Null; | |
| } | |
| }; | |
| "Time to get numbers from table: $($TableTime.TotalSeconds)"; | |
| $SequenceTime = Measure-Command { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| USE master; | |
| DROP DATABASE IF EXISTS SequenceTesting; | |
| GO | |
| CREATE DATABASE SequenceTesting; | |
| GO | |
| USE SequenceTesting; | |
| GO |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE sequence ABetterWay start | |
| WITH 1 increment BY 1; | |
| SELECT NEXT value | |
| FOR ABetterWay; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE TABLE SequenceHolder ( | |
| id INT identity(1, 1) | |
| ,BecauseINeedSomething BIT DEFAULT 0 | |
| ); | |
| CREATE OR ALTER PROCEDURE GetNextNumberTable | |
| AS | |
| BEGIN | |
| DECLARE @newid INT; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Original version | |
| SELECT DISTINCT location | |
| ,stuff(( | |
| SELECT ',' + cast(a2.npa AS CHAR(3)) | |
| FROM areacodes a2 | |
| WHERE a2.location = a.location | |
| order by a2.npa | |
| FOR XML PATH('') | |
| ), 1, 1, N'') AS areacodes | |
| FROM areacodes a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT location | |
| ,string_agg(npa, ',') AS AreaCodes | |
| FROM areacodes | |
| ORDER BY location; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT DISTINCT location | |
| ,stuff(( | |
| SELECT ',' + cast(a2.npa AS CHAR(3)) | |
| FROM areacodes a2 | |
| WHERE a2.location = a.location | |
| FOR XML PATH('') | |
| ), 1, 1, N'') AS areacodes | |
| FROM areacodes a | |
| ORDER BY location; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Original | |
| SELECT DISTINCT location | |
| ,stuff(( | |
| SELECT ',' + cast(a2.npa AS CHAR(3)) | |
| FROM areacodes a2 | |
| WHERE a2.location = a.location | |
| FOR XML PATH('') | |
| ), 1, 1, N'') AS areacodes | |
| FROM areacodes a | |
| ORDER BY location; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Get-Module -ListAvailable | ` | |
| Where-Object {$null -ne $PSItem.RepositorySourceLocation -and $PSItem.ModuleBase -like "$($env:Userprofile)*"} | ` | |
| Select-Object -Unique -Property Name | ` | |
| Update-Module; |