Asked: 8 months, 21 day(s) ago
Views: 72  |  Answers / Discussions: 6
Report

sql server 2005

IT
 Sort By: Date  |  Rating
Israr Ahmad
8 months, 21 day(s) ago

The CHECK constraint rejects any entry that contains an alpha character



Add CHECK programmatically



You can add a CHECK constraint programmatically when you create the table or after by executing a Transact-SQL (T-SQL) ALTER TABLE statement. The following T-SQL adds a new column to the example table:



USE AdventureWorks



ALTER TABLE dbo.PostalCodes



ADD PostalCodeExtended char(9) NULL



GO



ALTER TABLE dbo.PostalCodes



ADD CONSTRAINT CKPostalCodesPostalCodeExtended



CHECK (PostalCodeExtended LIKE



\'[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\')



GO



The first statement adds a character column named PostalCodeExtended. The next statement uses the ADD CONSTRAINT clause to add a CHECK constraint that forces number characters. The only difference is that this column expects a nine-character ZIP code value. Similarly to the manual example, the constraint will reject any value that contains an alpha character.



The image below shows what happens when you try to enter a value that's fewer than nine characters or that contains an alpha character -- the table accepts only one value, 406045555.


Guest352428
Guest352428
8 months, 21 day(s) ago

may i help you about the question you post on.


Answer the Question

sql server 2005

Enter the text you see in the image or reload
You are logged in from: 38.107.191.81
Subscribe for Updates
Enter your email to subscribe for maybenow updates on this topic

Become a Guide

Share your knowledge and help people by answering questions.

Guides

Malik Irfan Shaukat
Malik Irfan Shaukat
86 Points
0 Discussions
Tayyab
Tayyab
524 Points
129 Discussions
Vigorian
Vigorian
38 Points
2 Discussions
Musab
Musab
343 Points
60 Discussions
greg
greg
12 Points
0 Discussions
sql server 2005 posted in . . .