Questions tagged [check-constraint]

Check constraints in a relational database ensure that only certain values can be stored in one (or more columns). Check constraints can only validate columns of a single row.

Check constraints validate the value of one or more columns in a single row of a relational table. Typical check constraints are salary > 0 (validating a single column) or hire_date < fire_date (validating the dependency between two columns).

Check constraints can not be used to validate columns between different rows.

All relational DBMS except MySQL support check constraints.

77 questions
1
vote
1 answer

SQL Table Restriction

How can I specify, 5 distinct values for a varchar column in Oracle Application Express? I need a column called tipo_conta (varchar) that only accepts 'Conta a ordem', 'Multibanco', 'Rendimento', 'Jovem', 'Rendimento-Habitacao' as possible…
Dany4k
  • 83
  • 2
  • 11
1
vote
2 answers

Can I rename a check constraint on a table type in SQL Server 2014?

Through SQL Server 2014, CREATE TYPE ... TABLE does not support named check constraints. This in turn results in check constraints with cryptic names (e.g. CK__TT_Income__Incom__72BBEAA9). Such constraints are persisted in sys.check_constraints, but…
1
vote
2 answers

SQL I dont want to have names like alfred or Alfred or alfr in the same table

This is what I tried to do but it doesn't work : ALTER TABLE DEPT ADD CONSTRAINT DEPT_DNAME_CK CHECK (DNAME = 'ALF%');
Alfred.S.3
  • 23
  • 5
1
vote
1 answer

Password check-constraint SQL server

I'm trying to create a password constraint that must contain: -at least 1 Upper case -at least 1 number -at least 5 characters long I have searched a lot and i just can't make it work for example, i have tried this (len([PASSWORD])>(5) AND…
stefan
  • 165
  • 1
  • 15
1
vote
3 answers

Check constraint for string with a format in SQL Server

I have a table which is defined like: create table HLV ( id nvarchar(7) check (id LIKE 'HLV[0-9][0-9][0-9][0-9]') Primary key, birthday date, full_name nvarchar(20) NOT NULL, win int check (win > 0), lose int check (lose > 0), draw int check (draw >…
Tran Hoai Nam
  • 1,273
  • 2
  • 18
  • 35
1
vote
0 answers

SQL Server Multiple Foreign Keys - only allow and limit 1 foreign key to be set

I have the following SQL Table: Table: dbo.Document _________________________________________________ docID bigint (PK: required) docTypeID bigint (required) UploadName varchar(500) …
1
vote
2 answers

Check constraint using function

I have a table called Users with these columns: UserID (int) UserName (nvarchar), Password (nvarchar), isActive (bit - true/false). What I want to do is to allow insert of duplicate username only if all other users with this username are disabled.…
1
vote
1 answer

MySQL - Adding CHECK to a Column

Another what I am sure is a very basic MySQL question. Create Table MyTable ( zip char(5) CHECK (zip = '11111') ); Insert into MyTable Select '99999'; SELECT * From MyTable; --results in '99999' I restrict 'zip' to only the value '11111',…
J Brun
  • 1,246
  • 1
  • 12
  • 18
1
vote
0 answers

Oracle database data modeler check constraint

I need to create a check constraint on a date field on Oracle SQL developer 3.1.07 in domain administration. I created The check constraint and assigned my domain to field in logical schema. After conversione to relational schema The constraint is…
Mattiag
  • 108
  • 2
  • 10
1
vote
1 answer

Insert into partitioned table return violates check constraint but shouldn't

I've a table in a postgresql and I want it to be partitioned. The structure is below TABLE "DTD1"."logAdminActivity" ( "username" CHARACTER VARYING( 200 ) NOT NULL, "action" CHARACTER VARYING( 100 ) NOT NULL, "pk" CHARACTER VARYING( 5…
m hanif f
  • 406
  • 1
  • 7
  • 20
1
vote
1 answer

Check Constraint - how to make Check on the same parameters in the table?

I have table calls 'Users' and there is UserID there. I have also table calls UsersFriends that look like: create table UsersFriends ( UserID int references Users(UserID), FriendID int references Users(UserID), primary key(UserID,FriendID) ) As…
Zvi
  • 577
  • 6
  • 19
1
vote
2 answers

Table Check Constraint allows invalid data

When I create a check constraint using the test script below, then data which violates the constraint is still allowed into the table, and the constraint is still shown as trusted. I realize that the check constraint does not check for NULLs…
1
vote
2 answers

Is it possible to have a "deferred check constraint" in Oracle?

I was thinking that I'd like to have a "deferred check constraint" in Postgres, but that is apparently not supported at this time (Postgres 9.3) Then I saw that Oracle seems to broadly have "deferred" for its constraints, documented here. Therefore,…
starlocke
  • 3,407
  • 2
  • 25
  • 38
1
vote
1 answer

SQL Constraint that one column value cannot be greater than another in a different table

This probably isn't a very nice question as its blending business logic with DB structure, but its not my decision so: Is it possible to define a constraint the infers the value of one column (Table A, Column X) cannot be greater than the value of…
James
  • 1,237
  • 4
  • 22
  • 43
1
vote
1 answer

EF4 Automatic Check Constraints

How can I specify a Check Constraint in EF4 CodeFirst. Example: I have a string property for which I can have only specific values.
Babu James
  • 2,740
  • 4
  • 33
  • 50