constraints

Limit SQL Server column to a list of possible values

自闭症网瘾萝莉.ら 提交于 2019-12-20 10:20:50
问题 How do I put a constraint on a column so that it can only contain the following values? What do you call this type of constraint? Allowed values: "yes", "no" or "maybe" Column Data Type: nvarchar(5) DBMS: SQL Server 2008 回答1: you can use a CHECK constraint ALTER TABLE <table> ADD CONSTRAINT chk_val CHECK (col in ('yes','no','maybe')) MSDN link 回答2: Yes, check a constraint is it what you need. You can declare check constraint at the table declaration: CREATE TABLE test( _id BIGINT PRIMARY KEY

Declaring a default constraint when creating a table

岁酱吖の 提交于 2019-12-20 09:31:07
问题 I am creating a new table in Microsoft SQL server 2000 by writing the code instead of using the GUI, I am trying to learn how to do it "the manual way". This is the code I am actually using, and it works fine: CREATE TABLE "attachments" ( "attachment_id" INT NOT NULL, "load_date" SMALLDATETIME NOT NULL, "user" VARCHAR(25) NOT NULL, "file_name" VARCHAR(50) NOT NULL, CONSTRAINT "pk_attachments" PRIMARY KEY ("attachment_id"), CONSTRAINT "fk_users" FOREIGN KEY ("user") REFERENCES "users" ("user")

Get the unique constraint columns list (in TSQL)?

前提是你 提交于 2019-12-20 09:14:29
问题 I can get a list of unique constraints fairly easily with the following query: select * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where CONSTRAINT_TYPE='UNIQUE' But how do I get a list of the columns that each unique constraint applies to? 回答1: See INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE 回答2: Ed is correct, the columns are exposed on the constraint column usage view, here is the SQL for it. select TC.Constraint_Name, CC.Column_Name from information_schema.table_constraints TC inner join

Inherit from a generic base class, apply a constraint, and implement an interface in C#

大城市里の小女人 提交于 2019-12-20 09:13:45
问题 This is a syntax question. I have a generic class which is inheriting from a generic base class and is applying a constraint to one of the type parameters. I also want the derived class to implement an interface. For the life of me, I cannot seem to figure out the correct syntax. This is what I have: DerivedFoo<T1,T2> : ParentFoo<T1, T2> where T2 : IBar { ... } The first thing that came to mind was this: DerivedFoo<T1,T2> : ParentFoo<T1, T2> where T2 : IBar, IFoo { ... } But that is incorrect

What is the difference between primary, unique and foreign key constraints, and indexes?

主宰稳场 提交于 2019-12-20 08:43:42
问题 What is the difference between primary , unique and foreign key constraints , and indexes ? I work on Oracle 10g and SQL Server 2008 回答1: Primary Key and Unique Key are Entity integrity constraints Primary key allows each row in a table to be uniquely identified and ensures that no duplicate rows exist and no null values are entered. Unique key constraint is used to prevent the duplication of key values within the rows of a table and allow null values. (In oracle one null is not equal to

What is the difference between primary, unique and foreign key constraints, and indexes?

会有一股神秘感。 提交于 2019-12-20 08:42:12
问题 What is the difference between primary , unique and foreign key constraints , and indexes ? I work on Oracle 10g and SQL Server 2008 回答1: Primary Key and Unique Key are Entity integrity constraints Primary key allows each row in a table to be uniquely identified and ensures that no duplicate rows exist and no null values are entered. Unique key constraint is used to prevent the duplication of key values within the rows of a table and allow null values. (In oracle one null is not equal to

Inequality Constraint Ambiguity

眉间皱痕 提交于 2019-12-20 08:41:14
问题 i've a problem in resizing a UIView with Autolayout and constraints. I'd like to change the origin (less than or equal of original) and the width (greater than or equal of original) but I got this: Inequality Constraint Ambiguity Do you have idea for solve this? thanks 回答1: I tried to make more than 1 vertical spacing constraint shrink for 3.5" displays, so I had to make 2 constraints between components that I wanted to shrink on smaller screen. One constraint was inequality (greater or equal

Error when trying to update sqlite database in android

心已入冬 提交于 2019-12-20 07:27:25
问题 I had my database working but all the records I have inserted were for checking purpose, now I wanted to delete all the tables and creating new ones, so I tried updating the database by changing the version. I didn't change anything on the create table queries but I'm getting a foreign key constraint failed (code 787). Here is my DBHelper class: private static final String DATABASE_NAME = "roomatesDB"; // database version private static final int DATABASE_VERSION = 3; // tables name public

Why cannot delete from a table with reference to another

戏子无情 提交于 2019-12-20 07:09:09
问题 I have looked for answers but maybe I miss something. I have 2 tables see below. The entities from the first table is referenced from the second one, but when I try to delete from the second I get Error: foreign key mismatch . There are triggers (not show here), but they have nothing to do with DELETE or cmdauth . I do not understand why cannot remove row? CREATE TABLE app (name TEXT, script TEXT, PRIMARY KEY(name)); CREATE TABLE env (name TEXT, PRIMARY KEY(name)); CREATE TABLE role (name

setting up unique constraint on referenced columns in oracle 10g xe

一曲冷凌霜 提交于 2019-12-20 07:05:03
问题 I have the following situation. table looks like this CREATE TABLE CompetitionsLanguages ( competition REF CompetitionType SCOPE IS Competitions, language REF LanguageType SCOPE IS Languages ); I need this table to have a unique constraint on (competition,language) combination. oracle tells me that i cant put a UNIQUE or PK on columns that reference other tables. is it possible to somehow avoid the unique, using the CHECK, or some sort of a TRIGGER? 回答1: CREATE UNIQUE INDEX unqIndex ON