Link to home
Start Free TrialLog in
Avatar of katiewebster7
katiewebster7Flag for United States of America

asked on

SQL Server 2000 Data Types XNNNN

In sql server 2000 (windows), is it possible to set the data type when creating a new table to have a specific letter followed by four numbers, ie. J1004? It does not need to auto increment.
Example:
CREATE TABLE dbo.Employee  (
      vEmployeeID VARCHAR(5) UNIQUEIDENTIFIER PRIMARY KEY NONCLUSTERED,
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of katiewebster7

ASKER

that is not what I am looking for...

I am wanting to create a table that will only accept data for that field that begins with a specific letter, say, "J", followed by four numbers...
sorry - I just reread your post - yes, it seems like that would work - however, I am curious if that is truly the only way...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok, only "J" makes:
CREATE TABLE dbo.Employee  (
      vEmployeeID VARCHAR(5) PRIMARY KEY NONCLUSTERED CHECK (vEmployeeID like 'J[0-9][0-9][0-9][0-9]'))

Hope that helps ...

... as A3 said ... beating me by ten minutes ... :-)
>however, I am curious if that is truly the only way...
no, that's indeed not the only way (but the most effective one).

alternative would be a trigger that performs the same "check", and rolls back the transaction and raises an error to information the user (ie application) with the problem.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks a bunch - especially to angelIII !