constraint

Two column primary key in MySQL

I have a very simple problem and a solution that will work, but I'm looking for a simpler one. I'd like to prevent rows from being added to a database when multiple values equal existing values. For example, if a2=a1 AND b2=b1 then the data gets rejected. If only a2=a1 or only b2=b1 it is allowed. Basically I want it to act like a pr...

Should I use SQL triggers?

Hello, I am implementing a data base design that has a vehicle table, vehicle engine and vehicle gear table with SQL 2005. Each table has an ID that is a SQL identity number, and each engine and gear has a relation with the vehicle ID. So before I create a vehicle I must create an engine and gear. How could I know the vehicle identity...

Access via ODBC - Oracle DEFAULT not working

We use MS Access as a front-end to Oracle tables, via ODBC, and it has been working well. But we're trying to use the DEFAULT constraint in an Oracle table. When we open the linked table in Access, we see existing data just fine, but when we try to add a row, without keying any value into column(s) that have an Oracle DEFAULT (expecting...

How do i make mysql fail to insert a row when some column is not set?

Hi, I'm running into a problem where it is possible to insert a row into a table whithout specifically setting an INT NOT NULL column (defaults to 0 which is invalid for my purposes) I create the table this way: CREATE TABLE inventorycontrol ( ID INT NOT NULL UNIQUE AUTO_INCREMENT ,nodeID ...

How to copy between generic declared types with value type constraints

I have a generic method that copies values between value types. The following approaches give a design time error, even with the struct constraint. Any idea how I can copy or cast between the values? private Ttgt MyMethod<Tsrc,Ttgt>(Tsrc SourceObject) where Tsrc:struct where Ttgt:struct { //Error:cannot ...

Unique constraint on table column

Hi, I'm having a table (an existing table with data in it) and that table has a column UserName. I want this UserName to be unique. So I add a constraint like this: ALTER TABLE Users ADD CONSTRAINT [IX_UniqueUserUserName] UNIQUE NONCLUSTERED ([UserName]) Now I keep getting the Error that duplicate users exist in this table. But I ha...

SQL Constraints Question

In Sql Server 2005, I have a table with two integer columns, call them Id1 and Id2. I need them to be unique with in the table (easy enough with a unique index that spans both columns). I also need them to be unique in the table if the values are transposed between the two columns. For example, SELECT * FROM MyTable returns Id1 Id2 ...

How can I constrain multiple columns to prevent duplicates, but ignore null values?

Here's a little experiment I ran in an Oracle database (10g). Aside from (Oracle's) implementation convenience, I can't figure out why some insertions are accepted and others rejected. create table sandbox(a number(10,0), b number(10,0)); create unique index sandbox_idx on sandbox(a,b); insert into sandbox values (1,1); -- accepted ins...

Match between column values returned from LIKE constraint in SQL

Hi! I am trying to match column values returned, but values are returned as a result of pattern matching: select app.employees.id, app.employees.name, app.employees.current_bp, app.designation.designation from app.employees, app.designation where app.employees.id like 'khsn?' = app.designation.desig_id like 'khsn?'; As you can see,...

Unique constraint with 'ignore case'

How to specify custom constraint for Django model? Like that create table t ( login varchar(10), unique ( upper(login) ) ); ...

Can I remove the "not for replication" option from an existing check constraint in T-SQL?

Suppose a check constraint (involving multiple columns) with the "not for replication" option was added to a database table (e.g. "alter table table_name add constraint constraint_name check not for replication (constraint_expression)") I found syntax for dropping "not for replication" from a column, but not for an existing check constr...

validation on email / postcode fields in sql/oracle

Hi, Would be gratefull for some advice on the following - Is it possible to validate email and postcode fields through some kind of check constraint in the sql in oracle ? or this kind of thing as i suspect pl/sql with regular expressions ? Thanks ...

How to get the name of Constraint?

Hi, I am using MS Access Database and trying to full data from C# 2.0. How can i get the constriant name (Eg: name of Primarykey not the field name of primary key) using ADOX. Thanks in advance Madhu ...

How do you create an auto-incrementing revision number unique to a key in PGSQL?

Assuming I have the following tables. PARENT: PARENT_ID serial, DESCRIPTION character varying(50) CHILD: PARENT_ID integer, CHILD_ID integer, DESCRIPTION character varying(50) What I would like to see is each row in CHILD having a CHILD_ID that starts at 1 and increments by 1, unique per PARENT_ID. It would be similar to a revision n...

SQL: how to enforce that only a single column is set in a group of columns

In SQL, is there a way to enforce that only one column out of a group of columns has a value, and the others are null? Maybe a constraint or trigger? This type of thing might be for a lookup table, but are there any alternate table designs that might accomplish this better? For example: ID OtherTable1ID OtherTable2ID OtherTa...

How to put an interface constraint on a generic method in c# 3.5?

I want to achieve something like this in C# 3.5: public void Register<T>() : where T : interface {} I can do it with class or struct, but how to do it with an interface? Thanks! André ...

MySQL Foreign Key Constraint Confusion

Hey everyone, I have the following 'users' table in MySQL: CREATE TABLE `users` ( `uid` int(11) NOT NULL auto_increment, `fname` varchar(50) NOT NULL, `lname` varchar(50) NOT NULL, `role` varchar(75) NOT NULL, `region` tinyint(4) unsigned default NULL, `username` varchar(25) NOT NULL, `password` varchar(75) NOT NULL, `n...

C# Type Conversion Error Despite Generic Constraint

Why, with a generic constraint on type parameter T of class P of "must inherit from A", does the first call succeed but the second call fail with the type conversion error detailed in the comment: abstract class A { } static class S { public static void DoFirst(A argument) { } public static void DoSecond(ICollection<A> argument...

If you have a db table with a unique column (like "name"), how would you go about switching the names of two rows? (Using Hibernate, but it sounds like a problem across the board)

Let's say you had a table like this /------------ | id | name | |------------| | 1 | foo    | | 2 | bar    | ----------- There is a uniqueness constraint on the 'name' column. How would you set #2's name to foo, and #1's name to bar? I know you could probably just assign temporary names to both then stick in the desired names,...

Two columns in Mysql with uniqueness constraint between column1 and column2

Hi, Let us consider a user table: Username,email1,email2 Now, I want to make sure that no two rows in this table have any common email address. What would be the best way to ensure this ? E.g.: If table has row: "Bill,[email protected],[email protected]", then trying to insert a row like "Billy,[email protected],[email protected]" should give an ...