Rule in Sql Derver

  • How to create a rule in SQL Server which accpets only alpha numeric characters?

  • Try to avoid using RULES , instead use check constraints.

    RULES are going to be Deprecated in future releases

    http://msdn.microsoft.com/en-us/library/ms143729.aspx

    Jayanth Kurup[/url]

  • 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

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply