Ze Carioca Silva
Ze Carioca Silva

Reputation: 443

SQL table vs Entity Framework MVC

I know a little bit of MVC but I want to develop MVC with DataBase first. I want to know one thing. I saw in the internet a table like that:

CREATE TABLE dbo.Payroll 
    (
     ID int PRIMARY KEY, 
     PositionID INT, 
     Salary decimal(9,2),
     SalaryType nvarchar(10),  
     CHECK  (Salary > 10.00 and Salary < 150000.00) 
    );

I wanna know if the CHECK element will result in data-validation in my webSite .

thx in advance

Upvotes: 4

Views: 151

Answers (2)

codingbiz
codingbiz

Reputation: 26396

The validation won't be done in the web application/site but on the database. Just like a UNIQUE or FOREIGN KEY constraint, it would throw error/exception if that constraint is violated

See this fiddle: http://sqlfiddle.com/#!3/ede45 - remove the comment in the last line and see how it violates the constraints and throws error - which the user will see if not handled. You need to handle such entry before it gets to the database and the constraint would just be a double-check or cross-check

Upvotes: 1

lahsrah
lahsrah

Reputation: 9183

No, it won't automatically add validation on your website. It will enforce that constraint on the database and will "crash" if the user enters a value outside that range.

You should still add validation on the client side to prevent unhandled errors from the database.

Upvotes: 2

Related Questions