Groups | Blog | Home
all groups > sql server programming > may 2006 >

sql server programming : create custom id's


David Portas
5/7/2006 2:24:29 PM
[quoted text, click to view]

ALTER TABLE tbl
ADD id CHAR(6) NOT NULL
CONSTRAINT df_tbl_id DEFAULT ('0'),
CONSTRAINT ck_tbl_id CHECK (id LIKE '[A-Z0-9]%'),
CONSTRAINT pk_tbl PRIMARY KEY (id) ;

[quoted text, click to view]

ALTER TABLE other_tbl
ADD CONSTRAINT fk_other_tbl_tbl
FOREIGN KEY (id) REFERENCES tbl (id) ;

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--
Jason
5/7/2006 9:06:46 PM
Hi,

Can someone tell me how to create custom id's in sql server by using
user-defined functions.

I was thinking about creating a id with a length of 6. The first character
should by a alphanumeric.

Then i would like to have some sort of checkid function, if someone insert a
fictious id, it should raise an error.

Is this possible?

AddThis Social Bookmark Button