4

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

1
  • You have to enforce the same constraint on the front-end. If you didn't, an unhandled error or exception would be thrown that you must explicitly catch. You're not likely to do so. Commented Jan 31, 2013 at 23:02

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.