February 26, 2012 at 11:59 pm
How to create a rule in SQL Server which accpets only alpha numeric characters?
February 27, 2012 at 12:24 am
Try to avoid using RULES , instead use check constraints.
RULES are going to be Deprecated in future releases
February 27, 2012 at 6:50 am
Use check constraint as adviced in previous post. See the sample:
CREATE TABLE [dbo].[MyTbl](
[Id] [int] NOT NULL,
[AlphaNumericValue] [varchar](50) NULL
)
GO
ALTER TABLE [dbo].[MyTbl] WITH CHECK ADD CONSTRAINT [CK_MyTbl_AlphaNumericValue] CHECK ((NOT [AlphaNumericValue] like '%[^0-9A-Za-z]%'))
GO
ALTER TABLE [dbo].[MyTbl] CHECK CONSTRAINT [CK_MyTbl_AlphaNumericValue]
GO
insert MyTbl select 1, 'assddas'
insert MyTbl select 2, 'assddas1231231'
insert MyTbl select 3, '1231231'
insert MyTbl select 4, 'mnbasdk-asd' --this willl fail validation
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply