Skip to content

Commit

Permalink
v1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Spendolini authored and Brian Spendolini committed Aug 5, 2024
1 parent 383f2c3 commit 72729c2
Show file tree
Hide file tree
Showing 2 changed files with 290 additions and 0 deletions.
290 changes: 290 additions & 0 deletions labFiles/db_objects/deployment_script_azure.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,290 @@
/*
Deployment script for freedb
This code was generated by a tool.
Changes to this file may cause incorrect behavior and will be lost if
the code is regenerated.
*/

GO
SET ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS, ARITHABORT, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER ON;

SET NUMERIC_ROUNDABORT OFF;
GO

USE [freedb];


GO
IF EXISTS (SELECT 1
FROM [master].[dbo].[sysdatabases]
WHERE [name] = N'freedb')
BEGIN
ALTER DATABASE [freedb]
SET ANSI_NULLS ON,
ANSI_PADDING ON,
ANSI_WARNINGS ON,
ARITHABORT ON,
CONCAT_NULL_YIELDS_NULL ON,
QUOTED_IDENTIFIER ON,
ANSI_NULL_DEFAULT ON,
CURSOR_DEFAULT LOCAL
WITH ROLLBACK IMMEDIATE;
END


GO
IF EXISTS (SELECT 1
FROM [master].[dbo].[sysdatabases]
WHERE [name] = N'freedb')
BEGIN
ALTER DATABASE [freedb]
SET PAGE_VERIFY NONE,
DISABLE_BROKER
WITH ROLLBACK IMMEDIATE;
END


GO
ALTER DATABASE [freedb]
SET TARGET_RECOVERY_TIME = 0 SECONDS
WITH ROLLBACK IMMEDIATE;


GO
IF EXISTS (SELECT 1
FROM [master].[dbo].[sysdatabases]
WHERE [name] = N'freedb')
BEGIN
ALTER DATABASE [freedb]
SET QUERY_STORE (QUERY_CAPTURE_MODE = ALL, CLEANUP_POLICY = (STALE_QUERY_THRESHOLD_DAYS = 367), MAX_STORAGE_SIZE_MB = 100)
WITH ROLLBACK IMMEDIATE;
END


GO
IF EXISTS (SELECT 1
FROM [master].[dbo].[sysdatabases]
WHERE [name] = N'freedb')
BEGIN
ALTER DATABASE [freedb]
SET QUERY_STORE = OFF
WITH ROLLBACK IMMEDIATE;
END


GO
IF EXISTS (SELECT 1
FROM [master].[dbo].[sysdatabases]
WHERE [name] = N'freedb')
BEGIN
ALTER DATABASE [freedb]
SET TEMPORAL_HISTORY_RETENTION OFF
WITH ROLLBACK IMMEDIATE;
END


GO
PRINT N'Creating Table [dbo].[address]...';


GO
CREATE TABLE [dbo].[address] (
[address_id] INT IDENTITY (1, 1) NOT NULL,
[person_id] INT NOT NULL,
[address] NVARCHAR (200) NOT NULL,
PRIMARY KEY CLUSTERED ([address_id] ASC)
);


GO
PRINT N'Creating Table [dbo].[person]...';


GO
CREATE TABLE [dbo].[person] (
[person_id] INT IDENTITY (1, 1) NOT NULL,
[person_name] NVARCHAR (200) NOT NULL,
[person_email] NVARCHAR (200) NOT NULL,
[pet_preference] NVARCHAR (100) NOT NULL,
PRIMARY KEY CLUSTERED ([person_id] ASC)
);


GO
PRINT N'Creating Table [dbo].[todo]...';


GO
CREATE TABLE [dbo].[todo] (
[id] UNIQUEIDENTIFIER NOT NULL,
[title] NVARCHAR (1000) NOT NULL,
[completed] BIT NOT NULL,
[owner_id] VARCHAR (128) NOT NULL,
[position] INT NULL,
PRIMARY KEY NONCLUSTERED ([id] ASC)
);


GO
PRINT N'Creating Default Constraint <unnamed>...';


GO
ALTER TABLE [dbo].[todo]
ADD DEFAULT (newid()) FOR [id];


GO
PRINT N'Creating Default Constraint <unnamed>...';


GO
ALTER TABLE [dbo].[todo]
ADD DEFAULT ('public') FOR [owner_id];


GO
PRINT N'Creating Default Constraint <unnamed>...';


GO
ALTER TABLE [dbo].[todo]
ADD DEFAULT ((0)) FOR [completed];


GO
PRINT N'Creating Foreign Key [dbo].[FK_address_person]...';


GO
WAITFOR DELAY '00:00.010';

ALTER TABLE [dbo].[address] WITH NOCHECK
ADD CONSTRAINT [FK_address_person] FOREIGN KEY ([person_id]) REFERENCES [dbo].[person] ([person_id]);


GO
PRINT N'Creating Procedure [dbo].[delete_todo]...';


GO
CREATE PROCEDURE dbo.delete_todo
@id nvarchar(100),
@owner_id [varchar](128)
AS

BEGIN

delete from dbo.todo
where id = @id
and owner_id = @owner_id;

END;
GO
PRINT N'Creating Procedure [dbo].[get_person_by_pet]...';


GO
CREATE PROCEDURE dbo.get_person_by_pet
@pet nvarchar(100)
AS
BEGIN
select *
from dbo.person
where pet_preference = iif(NULLIF(@pet, '') IS NOT NULL,lower(@pet),lower(pet_preference));
END;
GO
PRINT N'Creating Procedure [dbo].[insert_todo]...';


GO
CREATE PROCEDURE dbo.insert_todo
@title nvarchar(1000),
@owner_id [varchar](128),
@order int
AS

BEGIN

insert into dbo.todo (title, owner_id, position)
OUTPUT INSERTED.*
values (@title, @owner_id, @order);

END;
GO
PRINT N'Creating Procedure [dbo].[update_todo]...';


GO
CREATE PROCEDURE dbo.update_todo
@id nvarchar(100),
@title nvarchar(1000) = NULL,
@owner_id [varchar](128),
@completed bit = NULL,
@order int = NULL
AS

BEGIN

update dbo.todo
set title = ISNULL(@title,title),
completed = ISNULL(@completed,completed),
position = ISNULL(@order,position)
OUTPUT INSERTED.*
where id = @id
and owner_id = @owner_id;

END;
GO
-- This file contains SQL statements that will be executed after the build script.

set identity_insert dbo.person on

insert into dbo.person(person_id, person_name, person_email, pet_preference) values(1,'Bill','[email protected]','Dogs');
insert into dbo.person(person_id, person_name, person_email, pet_preference) values(2,'Frank', '[email protected]','Cats');
insert into dbo.person(person_id, person_name, person_email, pet_preference) values(3,'Riley', '[email protected]','Cats');

set identity_insert dbo.person off

set identity_insert dbo.address on

insert into dbo.address (address_id, person_id, address) values (1, 1, 'Lincoln, MA');
insert into dbo.address (address_id, person_id, address) values (2, 2, 'Baltimore, MD');

set identity_insert dbo.address off

insert into dbo.todo
(
[id],
[title],
[completed],
[owner_id],
[position]
)
values
('00000000-0000-0000-0000-000000000001', N'Hello world', 0, 'public', 1),
('00000000-0000-0000-0000-000000000002', N'This is done', 1, 'public', 2),
('00000000-0000-0000-0000-000000000003', N'And this is not done (yet!)', 0, 'public', 4),
('00000000-0000-0000-0000-000000000004', N'This is a ☆☆☆☆☆ tool!', 0, 'public', 3),
('00000000-0000-0000-0000-000000000005', N'Add support for sorting', 1, 'public', 5)
;
GO

GO
PRINT N'Checking existing data against newly created constraints';


GO
USE [freedb];


GO
ALTER TABLE [dbo].[address] WITH CHECK CHECK CONSTRAINT [FK_address_person];


GO
PRINT N'Update complete.';


GO
File renamed without changes.

0 comments on commit 72729c2

Please sign in to comment.