Advertisement
otkalce

RBAC

May 20th, 2024
1,086
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.55 KB | Source Code | 0 0
  1. CREATE TABLE UserRole (
  2.     Id int NOT NULL IDENTITY (1, 1),
  3.     [Name] nvarchar(50) NOT NULL,
  4.     CONSTRAINT PK_UserRole PRIMARY KEY (Id)
  5. )
  6. GO
  7.  
  8. SET IDENTITY_INSERT UserRole ON
  9. GO
  10.  
  11. INSERT INTO UserRole (Id, [Name])
  12. VALUES
  13.     (1, 'Admin'),
  14.     (2, 'User')
  15. GO
  16.  
  17. SET IDENTITY_INSERT UserRole OFF
  18. GO
  19.  
  20. ALTER TABLE [USER]
  21. ADD RoleId int NULL
  22. GO
  23.  
  24. UPDATE [USER]
  25. SET RoleId = 2
  26. GO
  27.  
  28. ALTER TABLE [USER]
  29. ALTER COLUMN RoleId int NOT NULL
  30. GO
  31.  
  32. ALTER TABLE dbo.[USER]
  33. ADD CONSTRAINT FK_USER_UserRole FOREIGN KEY (RoleId)
  34. REFERENCES dbo.UserRole (Id)
  35. GO
  36.  
Tags: RBAC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement