database-integrity

What is the good approach to check an existance of unique values in database table by SqlAlchemy in python2.7

試著忘記壹切 提交于 2020-01-07 03:07:29
问题 I use session.merge in SqlAlchemy to insert data to the table with UniqueConstraint , which is common for several columns, for example, my ORM class has the following: UniqueConstraint("attr_1", "attr_2", "attr_3", name="attributes_uix") Should I use filter or filter_by with _and to check, if data, which I'm going to insert will violate this unique constraint, or is it the proper way to catch IntegrityError by try - except construction? 回答1: No an sql-alchemy expert but have struggled with

SQL Server: How to make server check all its check constraints?

时间秒杀一切 提交于 2019-12-28 05:16:08
问题 It seems that some scripts generated by Enterprise Manager* (or not, it doesn't matter) created check constraints WITH NOCHECK . Now when anyone modifies the table, SQL Server is stumbling across failed check constraints, and throwing errors. Can i make SQL go through all its check constraints, and check them? Running: sp_msforeachtable 'ALTER TABLE ? CHECK CONSTRAINT all' only enables previously disabled check constraints, it doesn't actually check them. Footnotes * SQL Server 2000 回答1: DBCC

SQL Server: How to make server check all its check constraints?

给你一囗甜甜゛ 提交于 2019-12-28 05:16:07
问题 It seems that some scripts generated by Enterprise Manager* (or not, it doesn't matter) created check constraints WITH NOCHECK . Now when anyone modifies the table, SQL Server is stumbling across failed check constraints, and throwing errors. Can i make SQL go through all its check constraints, and check them? Running: sp_msforeachtable 'ALTER TABLE ? CHECK CONSTRAINT all' only enables previously disabled check constraints, it doesn't actually check them. Footnotes * SQL Server 2000 回答1: DBCC

Rails 3: Validate combined values

二次信任 提交于 2019-12-03 03:01:17
问题 In Rails 2.x you can use validations to make sure you have a unique combined value like this: validates_uniqueness_of :husband, :scope => :wife In the corresponding migration it could look like this: add_index :family, [:husband, :wife], :unique => true This would make sure the husband/wife combination is unique in the database. Now, in Rails 3 the validation syntax changed and the scope attribute seems to be gone. It now looks like: validates :husband, :presence => true Any idea how I can

Rails 3: Validate combined values

六眼飞鱼酱① 提交于 2019-12-02 16:34:45
In Rails 2.x you can use validations to make sure you have a unique combined value like this: validates_uniqueness_of :husband, :scope => :wife In the corresponding migration it could look like this: add_index :family, [:husband, :wife], :unique => true This would make sure the husband/wife combination is unique in the database. Now, in Rails 3 the validation syntax changed and the scope attribute seems to be gone. It now looks like: validates :husband, :presence => true Any idea how I can achieve the combined validation in Rails 3? The Rails 2.x validations still work in Rails 3 so I can

How to fix possible db corruption?

守給你的承諾、 提交于 2019-11-29 14:44:53
I'm at a client doing some quick fixes to their access application. It was a while I had a go with access, but I'm recovering quickly. However, I've discovered an interesting problem: For some reports, I get a "Record is deleted" error. I've checked the reports, and it seems like there's a problem with one table. When opening that table, I find a record where all columns are marked "#deleted". So obviously, this row seems to be the culprit. However, when I try to delete that row, nothing really happens. If I re-open the table, the row still exists. Is there a corruption in the db? How can I

How to fix possible db corruption?

别等时光非礼了梦想. 提交于 2019-11-28 08:16:27
问题 I'm at a client doing some quick fixes to their access application. It was a while I had a go with access, but I'm recovering quickly. However, I've discovered an interesting problem: For some reports, I get a "Record is deleted" error. I've checked the reports, and it seems like there's a problem with one table. When opening that table, I find a record where all columns are marked "#deleted". So obviously, this row seems to be the culprit. However, when I try to delete that row, nothing

SQL Server: How to make server check all its check constraints?

你离开我真会死。 提交于 2019-11-27 18:47:50
It seems that some scripts generated by Enterprise Manager* (or not, it doesn't matter) created check constraints WITH NOCHECK . Now when anyone modifies the table, SQL Server is stumbling across failed check constraints , and throwing errors. Can i make SQL go through all its check constraints, and check them? Running: sp_msforeachtable 'ALTER TABLE ? CHECK CONSTRAINT all' only enables previously disabled check constraints, it doesn't actually check them. Footnotes * SQL Server 2000 Nathan DBCC CHECKCONSTRAINTS WITH ALL_CONSTRAINTS won't actually make your constraints trusted. It will report

IntegrityError duplicate key value violates unique constraint - django/postgres

人盡茶涼 提交于 2019-11-26 23:47:28
I'm following up in regards to a question that I asked earlier in which I sought to seek a conversion from a goofy/poorly written mysql query to postgresql. I believe I succeeded with that. Anyways, I'm using data that was manually moved from a mysql database to a postgres database. I'm using a query that looks like so: """ UPDATE krypdos_coderound cru set is_correct = case when t.kv_values1 = t.kv_values2 then True else False end from (select cr.id, array_agg( case when kv1.code_round_id = cr.id then kv1.option_id else null end ) as kv_values1, array_agg( case when kv2.code_round_id = cr_m.id

IntegrityError duplicate key value violates unique constraint - django/postgres

谁说我不能喝 提交于 2019-11-26 12:20:27
问题 I\'m following up in regards to a question that I asked earlier in which I sought to seek a conversion from a goofy/poorly written mysql query to postgresql. I believe I succeeded with that. Anyways, I\'m using data that was manually moved from a mysql database to a postgres database. I\'m using a query that looks like so: \"\"\" UPDATE krypdos_coderound cru set is_correct = case when t.kv_values1 = t.kv_values2 then True else False end from (select cr.id, array_agg( case when kv1.code_round