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?> I was thinking about creating a id with a length of 6. The first character
> should by a alphanumeric.
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) ;
> Then i would like to have some sort of checkid function, if someone insert
a
> fictious id, it should raise an error.
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
--
No comments:
Post a Comment