check-constraints

Postgresql: Violates check constraint. Failing row contains

江枫思渺然 提交于 2019-12-23 12:45:11
问题 I tried to insert some data in a database with postgresql but still showing the same message: ERROR: new row for relation "empleados" violates check constraint "ck_empleados_documento" DETAIL: Failing row contains (13, 22222222, f, Lopez, Ana, Colon 123, 1, 2, casado , 1990-10-10). I do not know where or what the error is nor did I find anything that solved this. This is what i try to insert: insert into empleados (documento, sexo, apellido, nombre, domicilio, idSecc, cantidadhijos,

How to write a query to ensure email contains @

我是研究僧i 提交于 2019-12-23 10:16:50
问题 I'm creating a database in db2 and I want to add a constrain to validate whether the user inserting a valid email address, that contain %@%.% . Without luck...any advice? 回答1: You can use LIKE with wildcards. See here for the wildcards on DB2. The underscore character ( _ ) represents any single character. The percent sign character (%) represents a string of zero or more characters. SELECT email FROM YourTable WHERE email NOT LIKE '%_@__%.__%' This will ignore the following cases (simple

SQL constraint to prevent updating a column based on its prior value

邮差的信 提交于 2019-12-23 10:16:06
问题 Can a Check Constraint (or some other technique) be used to prevent a value from being set that contradicts its prior value when its record is updated. One example would be a NULL timestamp indicating something happened, like "file_exported". Once a file has been exported and has a non-NULL value, it should never be set to NULL again. Another example would be a hit counter, where an integer is only permitted to increase, but can never decrease. If it helps I'm using postgresql, but I'd like

OCL constraints checking on Eclipse Papyrus

不羁的心 提交于 2019-12-22 10:57:34
问题 Does anyone manage to check OCL constraints on a class diagram modeled in Eclipse Papyrus ? I have definied a simple test profile with only one constraint on a stereotype attribute : {OCL} self.property > 0 The stereotype extends the Property metaclass so I applied it on a class attribute and I set the property of the stereotype to 0. But I never got an error with the Validation > Validate Model command from the context menu. Any help would be much appreciate. Thanks by advance. 回答1: I answer

Check constraint in SQL Server 2008

做~自己de王妃 提交于 2019-12-22 10:44:39
问题 Please, I just starting to learn SQL and got stuck. I'm trying to build a database for my test project, I've created some tables, did the relations, defined primary and foreign keys.....all of this in SQL Server 2008 through Visual interface (table design/edit), no statement coding (didn't get there yet, but I will :) ). I have a column Tax in a table called Orders and I did my homework and found that it's best to use a decimal data type (I used decimal(5, 2)) with a CHECK constraint. So I

Hibernate Check Annotation

落花浮王杯 提交于 2019-12-22 04:53:09
问题 I have a table with three fields, say a, b, c. I would like to add a constraint ensuring that if a is not null, then also b and c are not null. I have done that using following SQL ALTER TABLE sample ADD CONSTRAINT no_nulls CHECK (CASE WHEN a IS NOT NULL THEN b IS NOT NULL AND c IS NOT NULL END) Is there a way to achieve same effect using hibernate annotation @Check? I can't find a helpful example with that annotation, do developers tend not to use it at all? 回答1: Yes it is possible if @Check

How can I create a CHECK constraint on a VARCHAR column in SQL Server specifying a minimum data length?

谁说我不能喝 提交于 2019-12-18 05:37:28
问题 I have a VARCHAR(30) column in a Microsoft SQL Server database. I'd like to add a CHECK constraint that does not allow a value in the column to be less than 3 characters. What is the expression I must use? 回答1: use: ALTER TABLE [dbo].[YOUR_TABLE] ADD CONSTRAINT [MinLengthConstraint] CHECK (DATALENGTH([your_column]) > 2) Reference: DATALENGTH vs LEN SQL SERVER – 2005 Constraint on VARCHAR(MAX) Field To Limit It Certain Length 来源: https://stackoverflow.com/questions/4426005/how-can-i-create-a

How do I create a multiple-table check constraint?

女生的网名这么多〃 提交于 2019-12-17 09:21:59
问题 Please imagine this small database... Diagram removed dead ImageShack link - volunteer database diagram Tables Volunteer Event Shift EventVolunteer ========= ===== ===== ============== Id Id Id EventId Name Name EventId VolunteerId Email Location VolunteerId Phone Day Description Comment Description Start End Associations Volunteers may sign up for multiple events. Events may be staffed by multiple volunteers. An event may have multiple shifts. A shift belongs to only a single event. A shift

How do I add a custom CHECK constraint on a MySQL table?

心已入冬 提交于 2019-12-17 03:03:45
问题 I am having trouble with this table CREATE TABLE `Participants` ( `meetid` int(11) NOT NULL, `pid` varchar(15) NOT NULL, `status` char(1) DEFAULT NULL, PRIMARY KEY (`meetid`,`pid`), CONSTRAINT `participants_ibfk_1` FOREIGN KEY (`meetid`) REFERENCES `Meetings` (`meetid`) ON DELETE CASCADE CONSTRAINT `participants_ibfk_2` CHECK (status IN ('a','d','u')) CONSTRAINT `participants_ibfk_3` CHECK (pid IN (SELECT name FROM Rooms) OR pid IN (SELECT userid FROM People)) ); I want to have a foreign key

How do I add a custom CHECK constraint on a MySQL table?

蹲街弑〆低调 提交于 2019-12-17 03:03:20
问题 I am having trouble with this table CREATE TABLE `Participants` ( `meetid` int(11) NOT NULL, `pid` varchar(15) NOT NULL, `status` char(1) DEFAULT NULL, PRIMARY KEY (`meetid`,`pid`), CONSTRAINT `participants_ibfk_1` FOREIGN KEY (`meetid`) REFERENCES `Meetings` (`meetid`) ON DELETE CASCADE CONSTRAINT `participants_ibfk_2` CHECK (status IN ('a','d','u')) CONSTRAINT `participants_ibfk_3` CHECK (pid IN (SELECT name FROM Rooms) OR pid IN (SELECT userid FROM People)) ); I want to have a foreign key