Skip to content

Commit 399d26b

Browse files
Merge pull request #212 from JocaPC/master
Fixed scripts in json/react/nodejs sample
2 parents c930f62 + cbb98ce commit 399d26b

File tree

3 files changed

+55
-40
lines changed

3 files changed

+55
-40
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
select *
2+
from Comments
3+
for json path
4+
5+
select *
6+
from Comments
7+
where id = 1
8+
for json path, without_array_wrapper
9+
10+
declare @p nvarchar(4000) = N'[{"author":"John","text":"I like it too!"},{"author":"Jane","text":"Thanks!"},{"author":"Jane","text":"Buy :)"}]'
11+
12+
select *
13+
from openjson(@p)
14+
with ( author nvarchar(20), text nvarchar(200))
15+
16+
go
17+
18+
declare @p nvarchar(4000) = N'[{"author":"John","text":"I like it too!"},{"author":"Jane","text":"Thanks!"},{"author":"Jane","text":"Buy :)"}]'
19+
20+
insert into Comments(author, text)
21+
select *
22+
from openjson(@p)
23+
with ( author nvarchar(20), text nvarchar(200))
24+
25+
select *
26+
from Comments
27+
28+
select author, count(*) comments
29+
from Comments
30+
group by author
31+
for json path
32+
33+
delete Comments where id > 2
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
DROP LOGIN WebLogin
2+
CREATE LOGIN WebLogin WITH PASSWORD = 'SQLPass1234!'
3+
GO
4+
5+
DROP USER IF EXISTS WebUser
6+
CREATE USER WebUser FROM LOGIN WebLogin
7+
GO
8+
9+
DROP ROLE IF EXISTS WebUserRole
10+
CREATE ROLE WebUserRole
11+
GO
12+
13+
GRANT SELECT, INSERT, UPDATE, DELETE, EXECUTE TO WebUserRole
14+
EXEC sp_addrolemember N'WebUserRole', N'WebUser'
15+
GO
Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,14 @@
1-
--CREATE DATABASE TodoDb;
2-
--USE TodoDb;
3-
DROP TABLE IF EXISTS Todo
4-
DROP PROCEDURE IF EXISTS createTodo
5-
DROP PROCEDURE IF EXISTS updateTodo
1+
DROP TABLE IF EXISTS Comments
62
GO
73

8-
CREATE TABLE Todo (
4+
CREATE TABLE Comments (
95
id int IDENTITY PRIMARY KEY,
10-
title nvarchar(30) NOT NULL,
11-
description nvarchar(4000),
12-
completed bit,
13-
dueDate datetime2 default (dateadd(day, 3, getdate()))
6+
author nvarchar(30) NOT NULL,
7+
text nvarchar(4000)
148
)
159
GO
1610

17-
INSERT INTO Todo (title, description, completed, dueDate)
11+
INSERT INTO Comments (author, text)
1812
VALUES
19-
('Install SQL Server 2016','Install RTM version of SQL Server 2016', 0, '2017-03-08'),
20-
('Get new samples','Go to github and download new samples', 0, '2016-03-09'),
21-
('Try new samples','Install new Management Studio to try samples', 0, '2016-03-12')
22-
23-
GO
24-
25-
create procedure dbo.createTodo(@todo nvarchar(max))
26-
as begin
27-
insert into Todo
28-
select *
29-
from OPENJSON(@todo)
30-
WITH ( title nvarchar(30), description nvarchar(4000),
31-
completed bit, dueDate datetime2)
32-
end
33-
GO
34-
35-
create procedure updateTodo(@id int, @todo nvarchar(max))
36-
as begin
37-
update Todo
38-
set title = json.title, description = json.description,
39-
completed = json.completed, dueDate = json.dueDate
40-
from OPENJSON( @todo )
41-
WITH( title nvarchar(30), description nvarchar(4000),
42-
completed bit, dueDate datetime2) AS json
43-
where id = @id
44-
end
45-
go
46-
47-
select * from todo for json path
13+
('John','This is great!'),
14+
('Jane','I like the fact that it is simple.')

0 commit comments

Comments
 (0)