webForumDet fria alternativet

Panikfråga

Databaser & SQLur Databashanterare & SQL

1 svar · 210 visningar · startad av Bendro

Medlem sedan jan. 20013 039 inlägg
Frågan#1

Sitter och pluggar SQL och har fått en uppgift. Har letat efter svaret i Transact-SQL hjälpen och även i den enda bok jag har tillgänglig men hittar det inte där.

Frågan är "Vad är en CHECK-constraint?"

Finns det någon som kan ge mig ett bra svar eller kan tala om för mig var jag skall leta vore jag evigt tacksam.

------------------
"You can not solve todays problems with the same level of thinking that created the problems in the first place" Albert Einstein

Medlem sedan juni 200032 969 inlägg
#2

hej!

kort kan man säga att du begränsar tillåtna värden i en kolumn.

nedan på engelska ur sql server 7.0 books on line.

mvh,

CHECK constraints enforce domain integrity by limiting the values that are accepted by a column. They are similar to FOREIGN KEY constraints in that they control the values that are placed in a column. The difference is in how they determine which values are valid: FOREIGN KEY constraints get the list of valid values from another table, and CHECK constraints determine the valid values from a logical expression that is not based on data in another column. For example, it is possible to limit the range of values for a salary column by creating a CHECK constraint that allows only data that ranges from $15,000 to $100,000. This prevents salaries from being entered beyond the normal salary range.

You can create a CHECK constraint with any logical (Boolean) expression that returns TRUE or FALSE based on the logical operators. For the previous example, the logical expression is:

salary >= 15000 AND salary <= 100000

It is possible to apply multiple CHECK constraints to a single column. These are evaluated in the order in which they were created. It is also possible to apply a single CHECK constraint to multiple columns by creating it at the table level. For example, a multiple-column CHECK constraint can be used to confirm that any row with a country column value of USA also has a two-character value in the state column. This allows multiple conditions to be checked in one place.

------------------
<A HREF="http://cartman.nu" TARGET=_blank>
if i'm not back in five minutes, just wait longer.</A>

129 ms totalt · 3 externa anrop · v20260731065814-full.55e59744
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
125 ms — hämta tråd, inlägg och bilagor (db)