720 questions
-2
votes
1
answer
86
views
Adding CHECK Constraint Without Error and Duplication [duplicate]
I have implemented this code to add a check constraint after creating the table
ALTER TABLE recruitment_data.candidate_experiences
ADD CONSTRAINT chk_experience_dates
CHECK ( ...
0
votes
1
answer
99
views
How to do a negative foreign key check (constraint to foreign table) in MySQL?
I want to make sure, that a column doesn't have a value that exists in another column of another table. It is kind of like a negative foreign key check, if you will.
However adding a constraint doesn'...
0
votes
0
answers
50
views
MySQL UNIQUE still allows duplicate row insert when foreign key columns are NULL [duplicate]
I Have 3 tables ProdVariant, Variant, VariantValues.
ProductVariant
----------------------------
ProductVariantID PK
ProductID FK NOT NULL
VariantID FK NULL
...
1
vote
1
answer
248
views
How to add constraint if not exists
Adding constraint using
alter table dok add constraint dok_during_exclude EXCLUDE USING gist (pais2obj WITH =, during WITH &&)
throws error
ERROR: relation "dok_during_exclude" ...
-2
votes
2
answers
139
views
SQL Error [2290] [23000]: ORA-02290: check constraint (TEST_USER1.SYS_C008305) violated
CREATE TABLE Oracle_All_DataTypes (
ID NUMBER(10) PRIMARY KEY, -- Unique identifier
FirstName VARCHAR2(50) NOT NULL, -- First name must be provided
LastName VARCHAR2(50), -- Last name is ...
1
vote
1
answer
87
views
SQLite constraint for making 2 columns different
I have 2 SQLite tables, users and transactions where a "transaction" happens between exactly 2 users.
A short example would be:
CREATE TABLE users(
id INTEGER PRIMARY KEY ASC
);
CREATE ...
0
votes
1
answer
42
views
PostgreSQL: CheckConstraint based on another Column
In PostgreSQL, I want a check constraint if column "Art" (this never is NULL) is == 'Typ 3' and three other columns either all NULL or all NOT NULL.
My code fails for the first record having ...
-1
votes
1
answer
75
views
Are check constraints thread safe?
Can check constraint be used instead of pessimistic locks?
Consider there is following table in SQL Server:
create table Balances(
id int,
userId int,
balance money)
If more than 1 thread try to ...
1
vote
2
answers
78
views
Model field "null together or not at all" constraint
I need a way to create either a validator or a constraint at model level to evaluate two or more fields to be able to be null/blank only if all of them are null/blank at the same time.
For example, in ...
0
votes
1
answer
144
views
Django test a custom field in a test model using SqlLite3; cannot disable constraint checking to create database table
I need to write test for a custom field with access to the database.
The code is the following :
class TestMyField (TestCase):
def SetUpClass(cls):
super().setUpClass()
class MyModel(...
1
vote
4
answers
142
views
Create CHECK constraint based on complex algorithm
A personal identity codes consist of a string of numbers that indicates the individual’s date of birth, an individualized string, and a control character.
Example: 150600A905P
• 150600 = Date of birth ...
2
votes
1
answer
405
views
Stata: How do I check whether the value of one variable exists somewhere in the column of another variable?
I have two variables in Stata which are string (MAIDCW1 and strboth).
I would like to check for each observation whether the value of MAIDCW1 exists somewhere in the whole of strboth. If this value ...
0
votes
0
answers
96
views
How to check the type of *all* elements in a JSONArray within SQLite CHECK-constraint?
This is the Table in SQlite:
CREATE TABLE document(
id TEXT NOT NULL,
data TEXT NOT NULL,
CHECK ( json_type(data, '$.documentLines.title') IN ('text') ),
PRIMARY KEY (id)
) STRICT;
This ...
1
vote
2
answers
77
views
Check Constraint in Django
I want to include a check constraint for my model in my members app where the sex field should be male, female or null. Here is my code:
from django.db import models
from django.db.models import ...
-1
votes
1
answer
174
views
Without check constraint how Bigquery validate data?
We don't have application running on server,
so all the logic need to be done on Bigquery.
I know Microsoft SQL Server have check constraint like:
CREATE TABLE MyCleanJapanClient (
Phone varchar(...
0
votes
1
answer
66
views
CPlex: "No value" for all decision variables and how to solve conflicts
I run the code and the results is always "no value " for all decision variables. In the conflicts tab it shows:"ct20#1#10#4, ct21#1#10#4,ct22#1#10#4)", but I stuck and do not know ...
0
votes
1
answer
96
views
CPLEX: CP Optimizer took forever to run with no solution
I run my model in CPLEX using Constraint Programming for quite a long time, but it still has no solution so I have to stop the model.
Is there something wrong with my model? I tried to run the model ...
0
votes
1
answer
133
views
How to code nonlinear constraints in CPlex opl?
This is a part of my Cplex code. I want to code the constraint below but it seems nonlinear constraints and can not run in CPlex opl. Can anyone help me deal with it?
Here is the constraint
...
int ...
0
votes
2
answers
76
views
sql constraint in a check in
When creating a constraint for a hierarchy I get an error, it doesn't let me make inserts
I leave the code in case someone can give me a hand:
CREATE TABLE JUGADORES (
Id_jugador NUMBER (4) ...
-1
votes
1
answer
886
views
how can i put a check constraint to the phone number in mysql? [duplicate]
to check the phone number that it should be of the 10 digits , so how can i put the check constraint so that it will be validated
i try using the simple technique but i guess it will check only the ...
1
vote
1
answer
442
views
Creating a check constraint using liquibase
What are the options for adding check constraints to columns in tables when using Liquibase?
I have tried using the Liquibase checkConstraint attribute, but it doesn't seem to work, possibly because ...
1
vote
1
answer
23
views
Use CHECK to find if an IRM meetup has been done in the last two month
I need to create a table for meetup with patientId, doctorId, the meetupdate and the type.
And if the type is an IRM, I can't have another meetup if the last one as been less than 2 month ago.
I need ...
0
votes
1
answer
587
views
How to insert a check constraint
The aim is to insert a check constraint for the row titles, 'ppl_tshirt_size' that limits it to a few values (sm,med,lg,xl,xxl) but not an enum data type.
What am I not understanding? Additionally, ...
0
votes
0
answers
249
views
How can I specify the range of an integer in MariaDB?
I tried to add a column to my table where the integer needs to be in between 01067 and 99998. But The problem is that I don't know how to specify the range of an integer in SQL, so I tried it with the ...
0
votes
1
answer
61
views
Django CheckConstraint failing
I'm creating a custom user-model where every user needs a company assigned, unless they are a superuser or staff.
To accomplish this, I'm adding 3 CheckConstrains as seen below:
class CustomUser(...
1
vote
2
answers
163
views
Enforcing maximum number of relations in concurrent requests
I have these entities in my business:
class Team
{
public int Id { get; set; }
public string Name { get; set; }
public List<Member> Members { get; set; }
}
class Member
{
public ...
1
vote
1
answer
100
views
CHECK constraint matching beginning of value
We are using sqlite3 for a database and ensuring values inserted into a column matching a specific string would be useful in our case.
Example:
CREATE TABLE people ("firstname" TEXT),
CHECK(...
0
votes
1
answer
838
views
MariaDB 10.6 doesn't respect the foreign_key_checks setting when creating a table with check constraints
I'm trying to import database tables from a file of table definitions. Near the top, there is a line setting foreign_key_checks to 0, so that no errors would be thrown because of tables that ...
0
votes
0
answers
67
views
Check if new table entry has overlap with existing tables in PostgreSQL
I'm trying to write a constraint to check whether a new entry in my table has an overlay with already existing entries.
this is my code to add the constraint which doesnt work:
ALTER TABLE tour
...
0
votes
1
answer
514
views
How to bypass the check constraint in sql
Schema
create table course
(course_id varchar(8),
title varchar(50),
dept_name varchar(20),
credits numeric(2,0) check (credits > 0),
...
0
votes
1
answer
181
views
Postgres check constraint on `TEXT[]` using a normalized solution
Similar to other questions asked but haven't found a normalized solution for TEXT[]:
Postgres check constraint in text array for the validity of the values
does not use another table as a check
...
0
votes
1
answer
92
views
How can I implement a check constraint for attribute ID to start with specified letters?
I want my attribute ID to start with the letters AB, followed by exactly 8 integers. And how would I do it, when I want it to start and end with defined letters?
CREATE TABLE Table(
ID TEXT NOT ...
0
votes
1
answer
735
views
check constraints vs. triggers while both of them written in PLPg/SQL
I am using PostgreSQL 15.2; I can use both check constraints and triggers to ensure my business logic on database.
I read some of the comparisons about them, and I still have a question: if we can use ...
2
votes
1
answer
84
views
How to use check constraints in mysql table?
The values of produce_prices must be < wholesaler_prices must be < retailer_prices.
Can I apply check constraints for these to happen?
The table is the following:
CREATE TABLE `...
1
vote
1
answer
490
views
Adding a named check constraint to a table
I am trying to add a named CHECK constraint to a table in MariaDB. As far as I can tell from the documentation and a few samples scattered around, the following syntax shouyld work:
DROP TABLE IF ...
0
votes
1
answer
61
views
MySQL constraint to allow duplicates but prevent different combination of values in two column
A table in MySQL 8.0 where only one distinct combination of two values can exist. It can exist multiple times.
Example:
SQL Fiddle
Is there a way to do this without triggers?
UNIQUE CONSTRAINT won't ...
0
votes
1
answer
43
views
MS-Access 365 Table Level - Date Validation per Row
Working in MS Access 365 I am trying to set constraints on a table of appointment cycles. I was wondering how I can have the column CycleStartDate always be less than or equal to CycleEndDate; and ...
3
votes
1
answer
709
views
How to add a check constraint in django model that a field value startwith letter 'c' or 'e' or 'a'
How to add a check constraint in django model that a field value startwith letter 'c' or 'e' or 'a'
like the bellow SQL check constraint
CREATE TABLE Account (
account_no varchar(12),
...
1
vote
1
answer
212
views
How to include "CHECK" constraint to backup done via phpMyAdmin?
When I export my database from phpMyAdmin (quick method), it does not include CHECK constraints. However, when I run SHOW CREATE TABLE table, I see the constraints. Moreover, foreign constraints are ...
1
vote
1
answer
2k
views
Getting the column name of a postgres check constraint from information_schema
I can get the constraint name, the table name and the check_clause of the check constraints on a table using this query:
SELECT tc.constraint_type, tc.constraint_name, tc.table_name, cc.check_clause
...
1
vote
1
answer
1k
views
Prevent Postgres column to be EMPTY using supabase & prisma
I've started a new project using Prisma & Supabase but I'm facing an issue.
I have some required String columns. Is there a way to prevent those columns to accept empty string value ('').
Do you ...
1
vote
1
answer
120
views
CHECK constraint evaluation in SQL 92
when is check constraint evaluated as per SQL 92 standards?
create table a (
val INT
);
create table b (
f CHECK ( f in (SELECT val from a))
);
a) Is CHECK with sub-query allowed as per SQL-92 ...
2
votes
2
answers
335
views
Postgres CHECK() expression in column with array
I can't find how to check each element of an array-field in a table. Be like:
create table tab (
day_in_mounth int[12] check ( *every array element* > 0 and < 30)
);
values < 0 and > ...
-1
votes
1
answer
52
views
Can someone help? Im trying to create then modify a table. INSERT statement conflicted with the CHECK constraint "chk_Sex"
I am attempting to create a table then add and modify it. Below is how I created the table. The other part is the first record I attempted to add to the the table that has given me the check constrain ...
0
votes
1
answer
308
views
Add constraint on jsonb column to check if one of a set of strings in the columns values
What I am trying to accomplish is to create a constraint on a postgresql table’s column which is of type jsonb. The constraint will check and ensure that at least one of the values is in a predefined ...
0
votes
1
answer
133
views
How to write a CHECK constraint requiring 3 values
I am very new to SQL to apologize if this is a stupid question. I wanted to write a CHECK constraint requiring that a patient's medical record number, first name, and last name be entered. I believe ...
-1
votes
1
answer
48
views
Oracle SQL missing smth
Trying to build these tables and there's always an error or missing something, can someone help me?
Where's max_mice i'm checking if it's inbetween those values and doesn't work why?
Don't know what's ...
-1
votes
1
answer
122
views
How to make a check-constraint to control the data was inserted
I have a column named "ppl". How do I make a constraint for this column that the data inserted got to have 5 characters and start with "ppl" (the next 2 characters got to be ...
0
votes
0
answers
46
views
Case insensitive check constraint in SQL database creation
This is my create statement. I need to make a photo_filename constraint for it to be case insensitive to accept and form of .jpg JPG, JpG, jpG, etc.
CREATE TABLE P_PHOTO
(
PHOTO_ID CHAR(5) NOT ...
0
votes
0
answers
156
views
How can i drop a check constraint without deleting and recreating the table in sqlplus
I have this table and i added a check to the column duree
with this condition alter table operation modify Duree integer check(Duree>=2);
but in the homework it's specified that it needs to be like ...