Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
3 votes
2 answers
299 views

Why does MySQL generate a `key` statement in DDL for composite primary keys?

I am using MySQL version 8.3.0. I can create a “many to many” relationship between persons and teams tables with the following SQL statements: create table persons ( id bigint not null, last_name ...
Flow's user avatar
  • 356
3 votes
1 answer
2k views

Making a column unmodifiable/non-updatable after its row's initial creation?

What is the most idiomatic way to make a column unmodifiable/non-updatable after its initial creation via INSERT in Oracle? CREATE TABLE my_table ( id NUMBER NOT NULL CONSTRAINT ...
user avatar
4 votes
2 answers
339 views

Advantages to column constraints over table constraints

Is there any advantages whatsoever, other than style to writing this, CREATE TABLE foo ( a int PRIMARY KEY, b int ); And then, CREATE TABLE bar ( a int REFERENCES foo, c int ); Over, ...
Evan Carroll's user avatar
  • 64.7k
8 votes
4 answers
406 views

Can I specify a name for the index which SQL Server creates for my unique constraint?

In SQL Server I deploy a table with a UNIQUE constraint: CREATE TABLE [dbo].[Something] ( [IdentityId] UNIQUEIDENTIFIER UNIQUE NOT NULL DEFAULT NEWID() -- Whatever else... ) and this makes ...
sharptooth's user avatar
  • 1,331
1 vote
1 answer
1k views

How to add constraint on a varchar column to have at least one non numeric character

I am trying to implement some constraints on tables so that there is no tampering of the data from what is expected. One of the constraints is on a varchar column. It should at least contain one non-...
mayur rathi's user avatar
4 votes
2 answers
10k views

SQL Error: OA-12991 - Unable to Drop a Column after removing all referenced Multi-Column constraints

I am new to Oracle DB and am in need of some help. I would like to drop a specific column but i am getting a specific error. The issue specifically is: SQL Error: ORA-12991: column is reference ...
Rex Charles's user avatar
8 votes
1 answer
24k views

The ALTER TABLE statement conflicted with the CHECK constraint

I need to check datecom is less than datelivr create table Commande ( Numcom int identity primary key, Datecom date, Datelivr date, Codecli int foreign key references clients (Codecli) ) alter ...
Khalil B's user avatar
32 votes
3 answers
15k views

Constraint to enforce "at least one" or "exactly one" in a database

Say we have users and each user can have multiple email addresses CREATE TABLE emails ( user_id integer, email_address text, is_active boolean ) Some sample rows user_id | email_address | ...
Kevin Burke's user avatar
1 vote
2 answers
918 views

Default constraint issue

I have a table TempTable with one column having a default constraint ALTER TABLE [dbo].[TempTable] ADD CONSTRAINT [DF_TempTable_Version] DEFAULT ((1)) FOR [Version] Version is defined as decimal ...
Jeena's user avatar
  • 137
3 votes
4 answers
8k views

Find constraint disabled in SQL Server

I'm doing an audit of constraints in SQL Server. How to find all constraints that are not enabled? This, after using the next declaration: alter table mytable nocheck constraint all
Diego Flores's user avatar
0 votes
1 answer
192 views

What does a CONSTRAINT have to do with my unique index?

I have to indexes on my table. The first was created by Django and the second by me. I'm not completely certain what the extra CONSTRAINT means in the first index and am wondering how I would change ...
boatcoder's user avatar
  • 355
37 votes
2 answers
85k views

How do I drop all constraints from all tables?

I want to drop all default constraints, check constraints, unique constraints, primary keys and foreign keys from all tables in a SQL Server database. I know how to get all the constraint names from ...
Aaron Bertrand's user avatar
5 votes
1 answer
15k views

Check constraint references another column in same table

I have this table but check constraint is throwing me an error: Column CHECK constraint for column 'MedicamentRegulated' references another column, table 'Medicaments'. I've seen this as allowed ...
user avatar
60 votes
2 answers
61k views

MATCH FULL vs MATCH SIMPLE in foreign key constraints

I've noticed the clauses MATCH SIMPLE and MATCH FULL in phpPgAdmin, but I can't find a description in the docs. The default is MATCH SIMPLE. How do they function?
user avatar
1 vote
2 answers
210 views

Making a domain conditional on other values in the table

How can I define or change a domain based on another attribute value? F.e. domain for salary is a numeric value > 500. But if a date the person was hired > January 1st, 2013, then the salary must be >...
Ina's user avatar
  • 113
7 votes
1 answer
215 views

Is there anything a table-level constraint declaration can do that a column-level one can not do?

Had an exam today. One question disturbed me: What can a table-level constraint do that a column-level constraint can't do? My answer was that only a table-level constraint declaration permits ...
Stéphane Bruckert's user avatar