constraints

Get the unique constraint columns list (in TSQL)?

不想你离开。 提交于 2019-12-02 17:54:45
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? See INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE Andrew 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 information_schema.constraint_column_usage CC on TC.Constraint_Name = CC.Constraint_Name where TC.constraint

Ruby on Rails: How do I add a not null constraint to an existing column using a migration?

為{幸葍}努か 提交于 2019-12-02 16:53:59
In my Rails (3.2) app, I have a bunch of tables in my database but I forgot to add a few not null constraints. I've googled around but I can't find how to write a migration which adds not null to an existing column. TIA. For Rails 4+, nates' answer (using change_column_null ) is better. Pre-Rails 4, try change_column . You can also use change_column_null : change_column_null :table_name, :column_name, false 1) FIRST: Add column with default value 2) THEN: Remove default value add_column :orders, :items, :integer, null: false, default: 0 change_column :orders, :items, :integer, default: nil If

'NSInvalidArgumentException', reason: 'Unable to parse constraint format'

落花浮王杯 提交于 2019-12-02 15:44:05
I have a subview that I want to keep stops during rotating screen, so I decided to put the NSLayoutConstraint type: Trailing Space to Superview Top Space to Superview Button Space to Superview I'm in a subclass of UITableViewCell. I wrote the code but I get the following error: 'NSInvalidArgumentException', reason: 'Unable to parse constraint format: self is not a key in the views dictionary. H:[self.arrows]-5-| My code in CustomCell.m is: self.arrows = [[Arrows alloc]initWithFrame:CGRectMake(self.contentView.bounds.size.width-30, self.bounds.origin.y+4, 30, self.contentView.bounds.size.height

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

坚强是说给别人听的谎言 提交于 2019-12-02 15:15:41
What is the difference between primary , unique and foreign key constraints , and indexes ? I work on Oracle 10g and SQL Server 2008 Nadir SOUALEM 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 another null). KEY or INDEX refers to a normal non-unique index. Non-distinct values for the index

rightAnchor constraint did not apply when added programmatically - swift

♀尐吖头ヾ 提交于 2019-12-02 14:33:05
问题 When I Added rightAnchor constraint, constant= 20 did not apply. In leftAnchor is ok override init(frame: CGRect) { super.init(frame: frame) addSubview(collectionView) collectionView.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([collectionView.leftAnchor.constraint(equalTo: leftAnchor, constant: 20), collectionView.topAnchor.constraint(equalTo: self.topAnchor), collectionView.rightAnchor.constraint(equalTo: rightAnchor, constant: 20), collectionView

Techniques for Tracing Constraints

限于喜欢 提交于 2019-12-02 14:05:15
Here's the scenario: I've written some code with a type signature and GHC complains could not deduce x ~ y for some x and y . You can usually throw GHC a bone and simply add the isomorphism to the function constraints, but this is a bad idea for several reasons: It does not emphasize understanding the code. You can end up with 5 constraints where one would have sufficed (for example, if the 5 are implied by one more specific constraint) You can end up with bogus constraints if you've done something wrong or if GHC is being unhelpful I just spent several hours battling case 3. I'm playing with

SQL error: “name already used by an existing constraint”

拟墨画扇 提交于 2019-12-02 13:34:15
I'm trying to create some tables and setup the foreign keys but I keep encountering problems with the foreign keys. Earlier on I created the below table and it works fine CREATE TABLE inpatient (PatientNo varchar(6) NOT NULL, WardNo number(2), BedNo number(3) NOT NULL, OnWaitingList date, WardRequired varchar(25), ExpectStayInDays number(4), DatePlaced date, DateLeave date, ActualLeave date, constraint PatientFK foreign key (PatientNo) references Patient (patientNo), constraint bedFK foreign key (BedNo) references Bed (bedNo)); Notice the use of patientFK on 2nd last line. then I went on to

MySQL - Prevent Insertion of Record if ID and Timestamp Unique Combo Constraint Within Timeframe

China☆狼群 提交于 2019-12-02 13:28:42
I have a scenario in which 3 standalone agents are reporting uptime statuses for various hosts. If the hosts go down and are offline, a downtime record should be created. Unfortunately, since the agents report exactly at the same time with the same information, I've seen duplicate entries that are 1-2 seconds apart. I have a unique constraint that was created on the table for both the datetime and the host ID. Thus, they cannot be the same. But if the requests from the agents come in at the same time or a second apart, a duplicate might be created despite code checks looking for an existing

MySQL InnoDB constraint does not work

被刻印的时光 ゝ 提交于 2019-12-02 13:08:45
问题 I stumble upon strange behavior with innoDB constraint, and cannot find cause of it. I have tables with data. Below listed their structures: CREATE TABLE `contents` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `title` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`), KEY `title` (`title`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `fields` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(45) NOT NULL, `type` varchar(45) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY

R customized constraints optim function

佐手、 提交于 2019-12-02 12:27:36
Goal: Estimate sigma1 and sigma2 with the "optim" function, while sigma2 must be greater than sigma1 Simulate data (y) I have the following kind of data y: N<-50 delta<-matrix(rep(0, N*N), nrow=N, ncol=N) for(i in 1:(N )){ for (j in 1:N) if (i == j+1 | i == j-1){ delta[i,j] <- 1; } } sigma1<-5 sigma2<-10 diagonal=2*sigma1^2+sigma2^2 nondiag<--sigma1^2*delta Lambda_i<-(diag(diagonal,N)+-nondiag)/diagonal sig<-as.matrix(diagonal*Lambda_i) sig mu<-rep(0, N) y<-as.vector(mvnfast::rmvn(1,mu, sig)) Create maximum likelihood function mle<-function(par){ sigma1<-par[1] sigma2<-par[2] diagonal=2*sigma1