Advertisement
otkalce

Entity Framework - db structure, 1-to-many and many-to-many

Apr 5th, 2023
509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.98 KB | Source Code | 0 0
  1. CREATE TABLE [Tag] (
  2.     [Id] [int] IDENTITY(1,1) PRIMARY KEY NOT NULL,
  3.     [Name] [nvarchar](10) NOT NULL)
  4. GO
  5.  
  6. CREATE TABLE [dbo].[Genre](
  7.     [Id] [int] IDENTITY(1,1) PRIMARY KEY NOT NULL,
  8.     [Name] [nvarchar](256) NOT NULL)
  9. GO
  10.  
  11. CREATE TABLE [dbo].[Audio](
  12.     [Id] [int] IDENTITY(1,1) PRIMARY KEY NOT NULL,
  13.     [CreatedAt] [datetime2](7) NOT NULL,
  14.     [Title] [nvarchar](256) NOT NULL,
  15.     [GenreId] [int] NOT NULL,
  16.     [Duration] [int] NOT NULL,
  17.     [Url] [nvarchar](256) NULL)
  18. GO
  19.  
  20. CREATE TABLE [dbo].[AudioTag](
  21.     [Id] [int] IDENTITY(1,1) PRIMARY KEY NOT NULL,
  22.     [AudioId] [int] NOT NULL,
  23.     [TagId] [int] NOT NULL)
  24. GO
  25.  
  26. ALTER TABLE [dbo].[Audio]  
  27. ADD  CONSTRAINT [FK_Audio_Genre]
  28. FOREIGN KEY([GenreId])
  29. REFERENCES [dbo].[Genre] ([Id])
  30. GO
  31.  
  32. ALTER TABLE [dbo].[AudioTag]
  33. ADD  CONSTRAINT [FK_AudioTag_Audio]
  34. FOREIGN KEY([AudioId])
  35. REFERENCES [dbo].[Audio] ([Id])
  36. GO
  37.  
  38. ALTER TABLE [dbo].[AudioTag]  
  39. ADD  CONSTRAINT [FK_AudioTag_Tag]
  40. FOREIGN KEY([TagId])
  41. REFERENCES [dbo].[Tag] ([Id])
  42. GO
  43.  
Tags: db-relations
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement