Create a gist now

Instantly share code, notes, and snippets.

@amarkulo /.sql
Last active Aug 24, 2017

What would you like to do?
Import data to PwnedPwdDB
-- create table
USE [PwnedPwdDB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BadHashes](
[hash_id] [int] IDENTITY(1,1) NOT NULL,
[hash] [varchar](40) NOT NULL,
CONSTRAINT [Hashes_PK] PRIMARY KEY CLUSTERED
(
[hash_id] ASC
) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
-- add index
CREATE UNIQUE NONCLUSTERED INDEX [Hashes_Sorted_Index] ON [dbo].[BadHashes]
(
[hash] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = ON, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
-- create view
CREATE VIEW [dbo].[Hashes]
AS
SELECT hash
FROM dbo.BadHashes
GO
-- create user
USE [master]
GO
CREATE LOGIN [pwndbreader] WITH PASSWORD=N'pwndbreaderpassword', DEFAULT_DATABASE=[PwnedPwdDB], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO
USE [PwnedPwdDB]
GO
CREATE USER [pwndbreader] FOR LOGIN [pwndbreader]
GO
USE [PwnedPwdDB]
GO
ALTER USER [pwndbreader] WITH DEFAULT_SCHEMA=[db_datareader]
GO
USE [PwnedPwdDB]
GO
ALTER ROLE [db_datareader] ADD MEMBER [pwndbreader]
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment