-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbScript.sql
53 lines (50 loc) · 3.12 KB
/
dbScript.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
USE [MCS.DapperTest]
GO
/****** Object: Table [dbo].[tbl_Roles] Script Date: 6/19/2017 5:44:27 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tbl_Roles](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NOT NULL,
[Description] [nvarchar](100) NOT NULL,
[IsActive] [bit] NOT NULL,
CONSTRAINT [PK_tbl_Roles] PRIMARY KEY CLUSTERED
(
[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
/****** Object: Table [dbo].[tbl_Users] Script Date: 6/19/2017 5:44:28 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tbl_Users](
[Id] [bigint] IDENTITY(1,1) NOT NULL,
[FirstName] [nvarchar](50) NOT NULL,
[LastName] [nvarchar](50) NOT NULL,
[DateOfBirth] [date] NOT NULL,
[RoleId] [int] NOT NULL,
[IsActive] [bit] NOT NULL,
CONSTRAINT [PK_tbl_User] PRIMARY KEY CLUSTERED
(
[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
/****** Object: StoredProcedure [dbo].[sp_GetUsersByRole] Script Date: 6/19/2017 5:44:28 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[sp_GetUsersByRole]
@RoleId INT
AS
BEGIN
SELECT U.Id, U.RoleId, R.Name AS 'Role', U.FirstName, U.LastName, U.DateOfBirth FROM tbl_Users AS U
LEFT JOIN tbl_Roles AS R ON R.Id = U.RoleId
WHERE R.Id = @RoleId AND U.IsActive != 0
END
GO