Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase ««12

How to insert in 3 tables using stored procedure Expand / Collapse
Posted Sunday, September 22, 2013 6:42 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, October 21, 2013 3:10 AM
Points: 79, Visits: 191
L' Eomot Inversé (9/21/2013)
AndrewSQLDBA (9/20/2013)
This code is a waste, since @FirstName is an input parameter that will not allow a NULL. And the front-end should be checking the values for blanks, not the database.
IF @firstname = ''
RAISERROR ('[Error]No first name', 16, 1)

If that variable from the front-end gets all the way to the database with a blank space, you need to look at the code on the front-end.

I would recommend that you keep that code - relying on the front end to enforce domain constraints is a mistake. You should also have the column in the table declared
FirstName varchar(50) NOT NULL CHECK(LEN(FirstName) > 0)
since that's how domain constraints are expressed in T-SQL and you should want our tables to be in 1NF, which means the table definition must specify the domain of each attribute. Since the NULL values and zero length strings are not in the domain of this attribute, the table definition should say so.
Of course it's a good idea to have the front end check these things too - it can usually give a quicker and better response to a user who makes a mistake that it detects than if it lets the mistake through for the database to detect. But that doesn't absolve the database from responsibility for data integrity.

Thanks are so great ..cheers!!!
Post #1497250
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse