select dbo.validateCreditCard (@ccNumber). Where @ccNumber is a 16 digit lenght number in char format.
The function returns a bit datatype (1: valid number, or 0: invalid number)
CREATE FUNCTION dbo.validateCreditCard (
RETURNS bit AS
SET@isValidCC = 0
SET @CCNumber = LTRIM(RTRIM(@CCNumber))
IF (@CCNumber IS NULL) OR (LEN(@CCNumber) = 0) OR (ISNUMERIC(@CCNumber) <> 1)
SET @i = 1
SET @temp = 0
SET @TotalSum = 0
WHILE @i <= @lenCCNumber
IF SUBSTRING(@CCNumber,@i,1) NOT LIKE '[0-9]'
SET @temp = CAST(SUBSTRING(@CCNumber,@i,1) AS int)
IF (@i % 2) = 1
SET @temp = @temp * 2
IF @temp > 9
SET @temp = @temp - 9
SET @TotalSum = @TotalSum + @temp
SET @i = @i + 1
IF (@TotalSum % 10 = 0) AND (@TotalSum <= 150)
SET @isValidCC = 1
For most DBAs, normalization is an understood concept, a bread and butter bit of knowledge. However, it is not at all unusual to review a database design by a development group for an OLTP (OnLine Transaction Processing) environment and find that the schema chosen is anything but properly normalized. This article by Brian Kelley will give you the core knowledge to data model.
This article shows you how to design the storage for email addresses, how to validate email addresses, how to retrieve demographic information from email addresses efficiently, using computed columns and indexes. It also covers the security aspect of dealing with email addresses.