I am a student and working on a college project.
I have created a simple scenario which I am facing in my project.
The simple database looks like this.
**Location Table**
CREATE TABLE [dbo].[Location] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[longitude] VARCHAR (50) NULL,
[latitude] VARCHAR (50) NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
**Role Table**
CREATE TABLE [dbo].[Role] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[Name] VARCHAR (50) NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
**Another table**
CREATE TABLE [dbo].[Another] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[Anything] VARCHAR (50) NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
**User Table**
CREATE TABLE [dbo].[User] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[name] VARCHAR (50) NULL,
[address] VARCHAR (50) NULL,
[loc_id] INT NOT NULL,
[role_id] INT NOT NULL,
[another_id] INT NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_User_lococation] FOREIGN KEY ([loc_id]) REFERENCES [dbo].[Location] ([Id]),
CONSTRAINT [FK_User_another] FOREIGN KEY ([another_id]) REFERENCES [dbo].[Another] ([Id]),
CONSTRAINT [FK_User_role] FOREIGN KEY ([role_id]) REFERENCES [dbo].[Role] ([Id])
);
I have populated Role table with following values
enter image description here
Now I want to add user using EntityFrameWorkCore
My controller looks like this
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("Id,Name,Address,RoleId")] User user)
{
if (ModelState.IsValid)
{
_context.Add(user);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
ViewData["LocId"] = new SelectList(_context.Location, "Id", "Id", user.LocId);
ViewData["RoleId"] = new SelectList(_context.Role, "Id", "Id", user.RoleId);
return View(user);
}
The problem is I want to Add User but it doesn't have a foreign key of Location table and Another table.
How can I create a Location_id and Another_id and put in User
I want my User object to get the foreign key of location table and another table.
Please help me, I don't know how to do that it will great help for me.Thanks
If you don't have info about FK, don't generate it randomly, make foreign key column nullable in class user. Surely, when you are using EF you have navigation properties in User class. You can add also int property which stores id of associated entity (this is advised, so if you don't have, create such property). Type of this property should (obviously) nullable, so use int?. Then update database, so FK column in DB will be also nullable. Then you will be able to insert user entity.
Related
Creating shop application and having two main tables Product and Customer. The aim is to create an Order table where customer can choose from the productgetall list and add it to Order table.
Customer Table
CREATE TABLE [dbo].[Customer]
(
[CustomerId] INT IDENTITY (1, 1) NOT NULL,
[FirstName] NVARCHAR(40) NOT NULL,
[LastName] NVARCHAR(20) NOT NULL,
[Email] NVARCHAR(60) NOT NULL,
[Photo] VARBINARY(MAX) NULL,
[password] VARCHAR(300) NULL,
[Country] VARCHAR(50) NULL,
CONSTRAINT [PK_Customer]
PRIMARY KEY CLUSTERED ([CustomerId] ASC)
);
Product table:
CREATE TABLE [dbo].[Product]
(
[ProductId] INT IDENTITY (1, 1) NOT NULL,
[ProductName] NVARCHAR(50) NOT NULL,
[ProductDetails] TEXT NULL,
[ProductPrice] INT NOT NULL,
[ProductCategory] NVARCHAR(50) NULL,
PRIMARY KEY CLUSTERED ([ProductId] ASC)
);
Order table
CREATE TABLE [dbo].[Order]
(
[OrderId] INT IDENTITY (1, 1) NOT NULL,
[CustomerId] INT NOT NULL,
[ProductId] INT NOT NULL,
[Date] DATE NULL,
[Time] TIME(7) NULL,
CONSTRAINT [ORDER_PK]
PRIMARY KEY CLUSTERED ([OrderId] ASC),
CONSTRAINT [CUSTOMER_FK]
FOREIGN KEY ([CustomerId])
REFERENCES [dbo].[Customer] ([CustomerId])
ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT [PRODUCT_FK]
FOREIGN KEY ([ProductId])
REFERENCES [dbo].[Product] ([ProductId])
ON DELETE CASCADE ON UPDATE CASCADE
);
C# code to add order
public void AddOrder(Order a)
{
using (DbConnection conn = new SqlConnection(ConnStr))
{
using (DbCommand cmd = conn.CreateCommand())
{
cmd.CommandTimeout = 120;
cmd.CommandText = #"INSERT INTO [dbo].[Order] (CustomerId, ProductId, Date, Time)
VALUES (#CustomerId, #ProductId, #Date, #Time)";
cmd.AddParameter("#CustomerId", a.CustomerId, DbType.Int32);
cmd.AddParameter("#ProductId", a.ProductId, DbType.Int32);
cmd.AddParameter("#Date", a.Date, DbType.Date);
cmd.AddParameter("#Time", a.Time.ToString(), DbType.String);
conn.Open();
cmd.ExecuteScalar();
}
}
}
While creating through web forms it showing error on ExecuteScalar:
System.Data.SqlClient.SqlException: 'The INSERT statement conflicted with the FOREIGN KEY constraint "CUSTOMER_FK". The conflict occurred in database "C:\USERS\USER\DESKTOP\2019 5LVL\DBSD\TRYWISHLIST\3\00005466\00005466\APP_DATA\KFCDB.MDF", table "dbo.Customer", column 'CustomerId'. The statement has been terminated
The CustomerId you're sending does not exist in dbo.Customer, insert it.
I'm creating the following table:
CREATE TABLE [dbo].[Symptoms]
(
[Id] INT NOT NULL,
[description] NVARCHAR (128) NOT NULL,
[imgPath] NVARCHAR (128) NOT NULL,
[diseaseId] INT NOT NULL,
[weight] FLOAT NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC, [diseaseId] ASC)
);
What I want to do is create a default value for the [imgPath] column. I know about DEFAULT newid() and other methods, but I want a custom generated method.
Specifically, I want the [imgPath] to be $"/resources/Images/{Id}_symptom.jpg" where Id is the ID of that specific row.
Where can I specify this function?
Thanks!
Update
Column defaults in SQL Server can't be made up using other columns data.
What you can do is add another column for you to specify the image path, and use it as a part of the computed column's declaration:
CREATE TABLE [dbo].[Symptoms] (
[Id] INT NOT NULL,
[description] NVARCHAR (128) NOT NULL,
[UserDefinedImgPath] NVARCHAR (128) NULL,
[imgPath] AS COALESCE(UserDefinedimgPath, '/resources/Images/' + CAST(Id AS NVARCHAR(13)) +'_symptom.jpg') PERSISTED,
[diseaseId] INT NOT NULL,
[weight] FLOAT NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC, [diseaseId] ASC)
);
Now, when you want to specify the image page on insert or update, use the UserDefinedImgPath column. When you want the default value, simply leave it null.
When selecting the image path, always use the computed column.
First answer
Use a computed column for imgPath:
CREATE TABLE [dbo].[Symptoms] (
[Id] INT NOT NULL,
[description] NVARCHAR (128) NOT NULL,
[imgPath] AS '/resources/Images/' + CAST(Id AS NVARCHAR(13)) +'_symptom.jpg' PERSISTED,
[diseaseId] INT NOT NULL,
[weight] FLOAT NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC, [diseaseId] ASC)
);
Note that you can't update a computed column, nor can you insert a specific value to it.
To add default value please create default constraint, in SQL Server the example is below:
ALTER TABLE Symptoms
ADD CONSTRAINT Symptoms_imgPath
DEFAULT (('/resources/Images/{Id}_symptom.jpg')) FOR imgPath
Other way is to insert default value at the time of insert, like this:
INSERT INTO Symptoms
SELECT '/resources/Images/{Id}_symptom.jpg'
FROM symptoms
WHERE id = NEWID()
I'm trying to insert new text book records into a a database. I have a Course table with columns ID (PK), CourseID, CourseTitle.
textBook table (all columns, ID (PK)) is a many to many relationship so multiple courses can have the same book and courses can also have multiple different books.
When I try to insert a new text book into my database using C# I get an error on my foreign key. The Course table is parent, Textbook table is child. The ID column in both tables is set to identity and auto increments. ID is my foreign key in my textBook table referencing the Course table.
here is my intermediate table.
CREATE TABLE [dbo].[BookCourse]
(
[cID] INT NOT NULL Unique,
[BookID] INT NOT NULL Unique,
[BookCourseID] INT NOT NULL,
CONSTRAINT [PK_BookCourse] PRIMARY KEY ([BookCourseID])
)
here is my textBook table
CREATE TABLE [dbo].[textBooks] (
[thirteenISBN] VARCHAR (255) NOT NULL,
[CourseID] VARCHAR (50) NOT NULL,
[BookTitle] VARCHAR (255) NULL,
[Ancillary] VARCHAR (255) NULL,
[BookActive] VARCHAR (20) NULL,
[ActiveDate] VARCHAR (50) NULL,
[InactiveDate] VARCHAR (50) NULL,
[Author] VARCHAR (255) NULL,
[Imprint] VARCHAR (100) NULL,
[Publisher] VARCHAR (100) NULL,
[EditionAndDate] VARCHAR (120) NULL,
[tenISBN] VARCHAR (255) NULL,
[VendorISBN] INT NULL,
[ebookAvailable] VARCHAR (50) NULL,
[eISBN] VARCHAR (255) NULL,
[Notes] VARCHAR (255) NULL,
[BookID] INT IDENTITY (1, 1) NOT NULL,
CONSTRAINT [PK_textBooks] PRIMARY KEY CLUSTERED ([BookID] ASC),
CONSTRAINT [FK_textBooks_ToTable] FOREIGN KEY ([BookID]) REFERENCES [BookCourse]([BookID])
);
Here is my Course Table
CREATE TABLE [dbo].[Course] (
[CourseID] VARCHAR (50) NOT NULL,
[CourseTitle] VARCHAR (255) NULL,
[cID] INT IDENTITY (1, 1) NOT NULL,
CONSTRAINT [PK_Course] PRIMARY KEY CLUSTERED ([cID] ASC),
CONSTRAINT [FK_Course_ToTable] FOREIGN KEY ([cID]) REFERENCES [BookCourse]([cID])
);
Table Adapters with Insert:
JUTDMSTableAdapters.textBooksTableAdapter bookTableAdapter;
bookTableAdapter = new JUTDMSTableAdapters.textBooksTableAdapter();
JUTDMSTableAdapters.CourseTableAdapter courseTableAdapter;
courseTableAdapter = new JUTDMSTableAdapters.CourseTableAdapter();
courseTableAdapter.Insert( CourseID: txtCourseID.Text, CourseTitle: txtCourseTitle.Text);
bookTableAdapter.Insert( thirteenISBN: txt13ISBN.Text, CourseID: txtCourseID.Text, BookTitle: txtBookTitle.Text, Ancillary: txtAncillary.Text,
BookActive: txtBookActive.Text, ActiveDate: txtActiveDate.Text, InactiveDate: txtInactiveDate.Text, Author: txtAuthor.Text,
Imprint: txtImprint.Text, Publisher: txtPublisher.Text, EditionAndDate: txtEditionDate.Text,
VendorISBN: vendISBN, tenISBN: txt10ISBN.Text, ebookAvailable: txtEBookAvailable.Text, eISBN: txtEISBN.Text, Notes: txtNotes.Text);
I figured in my Course table adapter insert I wouldn't have to add the cID column seeing as it is auto increment but I get this error:
Additional information: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Course_ToTable". The conflict occurred in database "F:\HUTDMS V-2.0\HUTDMS V-2.0\APP_DATA\HUTDMS.MDF", table "dbo.BookCourse", column 'cID'.
BookID in the textbook table is autoincrement
cID in the Course table is autoincrement
BookCourseID in the BookCourse table is autoincrement.
For many-to-many relationship you need to use three tables, Book table, Course table and then intermediate table - BookCourse table. Book table refers BookCourse, Course Table refers BookCourse. There are NOT direct references between Book and Course tables
You first add book into Book table, then Course into Course table, finally you add the pair (CourseID, BookID) into BookCourse table.
As for BookCourse table, you may add composite primary key (CourseID, BookID), or add identity key BookCourseID, but if latter then you need to make sure there are no duplicates - you can create an unique constraint.
https://en.wikipedia.org/wiki/Many-to-many_(data_model)
After a lot of time working with ASP.NET Membership, at last I've some spare free time to dig into Identity and try to upgrade our developing framework to use it.
So... I'm reading a lot of info, tutorials into the matter and trying to put it to work.
At this moment, I've been able to register users into the database and assign roles to them. I've also changed the model to differenciate between username and email for user accounts, as usually into our applications we don't use email accounts for user identification.
However, I've hit a wall with login. When controller tries to execute PasswordSignInAsync I receive an unhandled exception like this:
System.Data.SqlClient.SqlException: Column name 'UserId' is not valid. Column name 'UserId' is not valid.
I'm totally lost with this problem, I don't see where those UserId columns are coming from (the only ones on database model are on AspNetUserRoles and in AspNetUserLogins) or why they aren't being recognized during query execution.
This is the controller Login action:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) {
if (!ModelState.IsValid) {
return View(model);
}
var result = await SignInManager.PasswordSignInAsync(model.username, model.Password, model.RememberMe, shouldLockout: true);
switch (result) {
case SignInStatus.Success:
return RedirectToLocal(returnUrl);
case SignInStatus.LockedOut:
return View("Lockout");
case SignInStatus.RequiresVerification:
return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
case SignInStatus.Failure:
default:
ModelState.AddModelError("", "Login error.");
return View(model);
}
}
The only change respect the base project is that I've changed the first parameter on the call from model.Email to model.username.
Any insight on the problem, how to trace or fix it will be much appreciated.
The problem could be that your database doesn't match the database model that your code is expecting.
Here's the ASP.NET Identity database as generated by code-first in a brand new ASP.NET MVC project with Identity from VS2013:
CREATE TABLE [dbo].[AspNetRoles] (
[Id] [nvarchar](128) NOT NULL,
[Name] [nvarchar](256) NOT NULL,
CONSTRAINT [PK_dbo.AspNetRoles] PRIMARY KEY ([Id])
)
CREATE UNIQUE INDEX [RoleNameIndex] ON [dbo].[AspNetRoles]([Name])
CREATE TABLE [dbo].[AspNetUserRoles] (
[UserId] [nvarchar](128) NOT NULL,
[RoleId] [nvarchar](128) NOT NULL,
CONSTRAINT [PK_dbo.AspNetUserRoles] PRIMARY KEY ([UserId], [RoleId])
)
CREATE INDEX [IX_UserId] ON [dbo].[AspNetUserRoles]([UserId])
CREATE INDEX [IX_RoleId] ON [dbo].[AspNetUserRoles]([RoleId])
CREATE TABLE [dbo].[AspNetUsers] (
[Id] [nvarchar](128) NOT NULL,
[Email] [nvarchar](256),
[EmailConfirmed] [bit] NOT NULL,
[PasswordHash] [nvarchar](max),
[SecurityStamp] [nvarchar](max),
[PhoneNumber] [nvarchar](max),
[PhoneNumberConfirmed] [bit] NOT NULL,
[TwoFactorEnabled] [bit] NOT NULL,
[LockoutEndDateUtc] [datetime],
[LockoutEnabled] [bit] NOT NULL,
[AccessFailedCount] [int] NOT NULL,
[UserName] [nvarchar](256) NOT NULL,
CONSTRAINT [PK_dbo.AspNetUsers] PRIMARY KEY ([Id])
)
CREATE UNIQUE INDEX [UserNameIndex] ON [dbo].[AspNetUsers]([UserName])
CREATE TABLE [dbo].[AspNetUserClaims] (
[Id] [int] NOT NULL IDENTITY,
[UserId] [nvarchar](128) NOT NULL,
[ClaimType] [nvarchar](max),
[ClaimValue] [nvarchar](max),
CONSTRAINT [PK_dbo.AspNetUserClaims] PRIMARY KEY ([Id])
)
CREATE INDEX [IX_UserId] ON [dbo].[AspNetUserClaims]([UserId])
CREATE TABLE [dbo].[AspNetUserLogins] (
[LoginProvider] [nvarchar](128) NOT NULL,
[ProviderKey] [nvarchar](128) NOT NULL,
[UserId] [nvarchar](128) NOT NULL,
CONSTRAINT [PK_dbo.AspNetUserLogins] PRIMARY KEY ([LoginProvider], [ProviderKey], [UserId])
)
CREATE INDEX [IX_UserId] ON [dbo].[AspNetUserLogins]([UserId])
ALTER TABLE [dbo].[AspNetUserRoles] ADD CONSTRAINT [FK_dbo.AspNetUserRoles_dbo.AspNetRoles_RoleId] FOREIGN KEY ([RoleId]) REFERENCES [dbo].[AspNetRoles] ([Id]) ON DELETE CASCADE
ALTER TABLE [dbo].[AspNetUserRoles] ADD CONSTRAINT [FK_dbo.AspNetUserRoles_dbo.AspNetUsers_UserId] FOREIGN KEY ([UserId]) REFERENCES [dbo].[AspNetUsers] ([Id]) ON DELETE CASCADE
ALTER TABLE [dbo].[AspNetUserClaims] ADD CONSTRAINT [FK_dbo.AspNetUserClaims_dbo.AspNetUsers_UserId] FOREIGN KEY ([UserId]) REFERENCES [dbo].[AspNetUsers] ([Id]) ON DELETE CASCADE
ALTER TABLE [dbo].[AspNetUserLogins] ADD CONSTRAINT [FK_dbo.AspNetUserLogins_dbo.AspNetUsers_UserId] FOREIGN KEY ([UserId]) REFERENCES [dbo].[AspNetUsers] ([Id]) ON DELETE CASCADE
Compare your database to this structure and it should work :)
I am in the process of building the website for the Linq, and the way that I need is to use Foreign keys to precisely set the same with my users table.ยจ
I have assured me that my Tabler has a primary key because it must be unique content that use grab.
Its a brugere table
CREATE TABLE [dbo].[brugere] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[username] NVARCHAR (255) NOT NULL,
[password] NVARCHAR (255) NOT NULL,
CONSTRAINT [PK_brugere] PRIMARY KEY ([Id]),
CONSTRAINT [FK_brugere_ToPoint] FOREIGN KEY ([Id]) REFERENCES [pointantal]([brugerid]),
CONSTRAINT [FK_brugere_ToKunde] FOREIGN KEY ([Id]) REFERENCES [KundeData]([brugerid])
);
Poinantal its here
CREATE TABLE [dbo].[pointantal] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[point] INT NOT NULL,
[omrade] NVARCHAR (255) NOT NULL,
[datotid] DATETIME DEFAULT (getdate()) NOT NULL,
[brugerid] INT NOT NULL,
CONSTRAINT [PK_pointantal] PRIMARY KEY ([Id])
);
and KundeData table here
CREATE TABLE [dbo].[KundeData] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[Adresse] NVARCHAR (255) NOT NULL,
[Postnr] INT NOT NULL,
[Mobil] INT NOT NULL,
[Byen] NVARCHAR (255) NOT NULL,
[abonnementsId] INT NOT NULL,
[BuyDate] DATETIME DEFAULT (getdate()) NOT NULL,
[prisid] INT NOT NULL,
[HaevedeId] NVARCHAR (255) NULL,
[brugerid] INT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
The error message I receive when I try to updater content is here
Update cannot proceed due to validation errors.
Please correct the following errors and try again.
SQL71516 :: The referenced table '[dbo].[pointantal]' contains no
primary or candidate keys that match the referencing column list in
the foreign key. If the referenced column is a computed column, it
should be persisted. SQL71516 :: The referenced table
'[dbo].[KundeData]' contains no primary or candidate keys that match
the referencing column list in the foreign key. If the referenced
column is a computed column, it should be persisted.
A foreign key can only reference a primary key or unique column. You can either add a unique constraint to the columns that you are referencing:
CREATE TABLE [dbo].[pointantal] (
...
CONSTRAINT AK_BrugerID UNIQUE(brugerid)
Or you can change your constraint to actually reference the primary key in your tables:
CONSTRAINT [FK_brugere_ToPoint] FOREIGN KEY ([Id]) REFERENCES [pointantal]([Id])
However, it seems like you really want the brugerid column of the pointantal and KundeData tables to access an Id (which is a unique column) in the brugere table. In this case, you put the foreign key on those tables and have it access the primary key of the bruger table. The following code runs sucessfully on my system:
CREATE TABLE [dbo].[brugere] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[username] NVARCHAR (255) NOT NULL,
[password] NVARCHAR (255) NOT NULL,
CONSTRAINT [PK_brugere] PRIMARY KEY ([Id])
);
CREATE TABLE [dbo].[pointantal] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[point] INT NOT NULL,
[omrade] NVARCHAR (255) NOT NULL,
[datotid] DATETIME DEFAULT (getdate()) NOT NULL,
[brugerid] INT NOT NULL,
CONSTRAINT [PK_pointantal] PRIMARY KEY ([Id]),
CONSTRAINT [FK_point_ToBrugere] FOREIGN KEY ([brugerid]) REFERENCES [brugere]([Id])
);
a foreign key is a field (or collection of fields) in one table that
uniquely identifies a row of another table. In simpler words, the
foreign key is defined in a second table, but it refers to the primary
key in the first table.
Try:
1>Change the Reference column
CREATE TABLE [dbo].[pointantal] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[point] INT NOT NULL,
[omrade] NVARCHAR (255) NOT NULL,
[datotid] DATETIME DEFAULT (getdate()) NOT NULL,
[brugerid] INT NOT NULL,
CONSTRAINT [PK_pointantal] PRIMARY KEY ([Id])
);
CREATE TABLE [dbo].[KundeData] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[Adresse] NVARCHAR (255) NOT NULL,
[Postnr] INT NOT NULL,
[Mobil] INT NOT NULL,
[Byen] NVARCHAR (255) NOT NULL,
[abonnementsId] INT NOT NULL,
[BuyDate] DATETIME DEFAULT (getdate()) NOT NULL,
[prisid] INT NOT NULL,
[HaevedeId] NVARCHAR (255) NULL,
[brugerid] INT NOT NULL,
PRIMARY KEY CLUSTERED ([Id])
);
CREATE TABLE [dbo].[brugere] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[username] NVARCHAR (255) NOT NULL,
[password] NVARCHAR (255) NOT NULL,
CONSTRAINT [PK_brugere] PRIMARY KEY ([Id]),
CONSTRAINT [FK_brugere_ToPoint] FOREIGN KEY ([Id]) REFERENCES [pointantal]([Id]),
CONSTRAINT [FK_brugere_ToKunde] FOREIGN KEY ([Id]) REFERENCES [KundeData]([Id])
);
2>Change The Primary-Key
CREATE TABLE [dbo].[pointantal] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[point] INT NOT NULL,
[omrade] NVARCHAR (255) NOT NULL,
[datotid] DATETIME DEFAULT (getdate()) NOT NULL,
[brugerid] INT NOT NULL,
CONSTRAINT [PK_pointantal] PRIMARY KEY ([brugerid])
);
CREATE TABLE [dbo].[KundeData] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[Adresse] NVARCHAR (255) NOT NULL,
[Postnr] INT NOT NULL,
[Mobil] INT NOT NULL,
[Byen] NVARCHAR (255) NOT NULL,
[abonnementsId] INT NOT NULL,
[BuyDate] DATETIME DEFAULT (getdate()) NOT NULL,
[prisid] INT NOT NULL,
[HaevedeId] NVARCHAR (255) NULL,
[brugerid] INT NOT NULL,
PRIMARY KEY CLUSTERED ([brugerid])
);
CREATE TABLE [dbo].[brugere] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[username] NVARCHAR (255) NOT NULL,
[password] NVARCHAR (255) NOT NULL,
CONSTRAINT [PK_brugere] PRIMARY KEY ([Id]),
CONSTRAINT [FK_brugere_ToPoint] FOREIGN KEY ([Id]) REFERENCES [pointantal]([brugerid]),
CONSTRAINT [FK_brugere_ToKunde] FOREIGN KEY ([Id]) REFERENCES [KundeData]([brugerid])
);