1
0
mirror of https://github.com/Microsoft/sql-server-samples.git synced 2025-12-08 14:58:54 +00:00
Files
sql-server-samples/samples/features/json/angularjs/dotnet-tour-of-heroes/sql-scripts/setup.sql
Jovan Popovic 08cce021ee AngularJS Hero app
Working version of Hour of heroes app.
2016-10-29 09:34:49 -07:00

43 lines
838 B
Transact-SQL

use HeroDb;
go
drop table if exists Hero;
drop procedure if exists InsertHero;
go
create table Hero (
id int primary key identity,
name nvarchar(40)
);
go
declare @heroes nvarchar(4000) =
N'[
{ "name": "Mr. Nice" },
{ "name": "Narco" },
{ "name": "Bombasto" },
{ "name": "Celeritas" },
{ "name": "Magneta" },
{ "name": "RubberMan" },
{ "name": "Dynama" },
{ "name": "Dr IQ" },
{ "name": "Magma" },
{ "name": "Tornado" }
]';
insert into Hero(name)
select name
from openjson(@heroes) with (name nvarchar(40));
GO
CREATE PROCEDURE dbo.InsertHero(@hero nvarchar(4000))
AS BEGIN
insert into Hero(name)
select name
from openjson(@hero) with (name nvarchar(40));
-- put generated id in @hero JSON object and return it back to client.
select JSON_MODIFY(@hero, '$.id', @@IDENTITY)
END