Apart from the four system databases, we already knew, Microsoft has introduced a new database…
A vital part of most system in Sweden is the “personnummer”.
Example SELECT dbo.TenModulo10UF(5511300115)
IF OBJECT_ID(N’dbo.TenModulo10UF’) IS NOT NULL DROP FUNCTION dbo.TenModulo10UF GO CREATE FUNCTION dbo.TenModulo10UF (@value bigint) RETURNS integer AS BEGIN DECLARE @s varchar(20) , @n integer , @i integer = 1 , @Return integer = 0 , @s2 varchar(20) = ” SET @s = CAST(@value as varchar(20)) IF DATALENGTH(@s) > 10 OR DATALENGTH(@s) < 10
You can also add the function as a check constraint:
CREATE TABLE dbo.Persons(PersonNummer bigint NOT NULL) GO ALTER TABLE dbo.Persons ADD CONSTRAINT CheckPnr CHECK (dbo.TenModulo10UF(PersonNummer)= 1) GO