Skip to content

Instantly share code, notes, and snippets.

@bertwagner
Created February 19, 2017 13:43
Show Gist options
  • Save bertwagner/72bae57d890d8b4b41b6bb9f708afee4 to your computer and use it in GitHub Desktop.
Save bertwagner/72bae57d890d8b4b41b6bb9f708afee4 to your computer and use it in GitHub Desktop.
Test data for SQL performance comparison (truncated)
-- Car data source: https://github.com/arthurkao/vehicle-make-model-data
IF OBJECT_ID('dbo.Cars') IS NOT NULL
BEGIN
DROP TABLE dbo.Cars;
END
CREATE TABLE dbo.Cars
(
Id INT IDENTITY(1,1),
CarDetails NVARCHAR(MAX)
);
-- See https://gist.github.com/bertwagner/1df2531676112c24cd1ab298fc750eb2 for the full untruncated version of this code
DECLARE @cars nvarchar(max) = '[ {"year":2001,"make":"ACURA","model":"CL"}, {"year":2001,"make":"ACURA","model":"EL"},...]';
INSERT INTO dbo.Cars (CarDetails)
SELECT value FROM OPENJSON(@cars, '$');
SELECT * FROM dbo.Cars;
/*
Output:
Id CarDetails
----------- ----------------------------------------------
1 {"year":2001,"make":"ACURA","model":"CL"}
2 {"year":2001,"make":"ACURA","model":"EL"}
3 {"year":2001,"make":"ACURA","model":"INTEGRA"}
...
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment