truncate

I got error “The DELETE statement conflicted with the REFERENCE constraint”

随声附和 提交于 2019-11-26 09:58:15
问题 I tried to truncate a table with foreign keys and got the message: \" Cannot truncate table because it is being referenced by a FOREIGN KEY constraint \". I read a lot of literature about the problem and thought that I found the solution by using delete DELETE FROM table_name DBCC CHECKIDENT (table_name, RESEED, 0) But I still got an error message: \" The DELETE statement conflicted with the REFERENCE constraint \". When I try to delete with Microsoft Management Studio and execute the

How to check if UILabel is truncated?

自古美人都是妖i 提交于 2019-11-26 09:16:27
问题 I have a UILabel that can be varying lengths depending on whether or not my app is running in portrait or landscape mode on an iPhone or iPad. When the text is too long to show on one line and it truncates I want the user to be able to press it and get a popup of the full text. How can I check to see if the UILabel is truncating the text? Is it even possible? Right now I\'m just checking for different lengths based on what mode I\'m in but it does not work super well. 回答1: You can calculate

SQL Server silently truncates varchar's in stored procedures

亡梦爱人 提交于 2019-11-26 08:09:20
问题 According to this forum discussion, SQL Server (I\'m using 2005 but I gather this also applies to 2000 and 2008) silently truncates any varchar s you specify as stored procedure parameters to the length of the varchar, even if inserting that string directly using an INSERT would actually cause an error. eg. If I create this table: CREATE TABLE testTable( [testStringField] [nvarchar](5) NOT NULL ) then when I execute the following: INSERT INTO testTable(testStringField) VALUES(N\'string which

Postgresql Truncation speed

笑着哭i 提交于 2019-11-26 07:00:20
问题 We\'re using Postgresql 9.1.4 as our db server. I\'ve been trying to speed up my test suite so I\'ve stared profiling the db a bit to see exactly what\'s going on. We are using database_cleaner to truncate tables at the end of tests. YES I know transactions are faster, I can\'t use them in certain circumstances so I\'m not concerned with that. What I AM concerned with, is why TRUNCATION takes so long (longer than using DELETE) and why it takes EVEN LONGER on my CI server. Right now, locally

Limiting double to 3 decimal places

≯℡__Kan透↙ 提交于 2019-11-26 06:36:31
问题 This i what I am trying to achieve: If a double has more than 3 decimal places, I want to truncate any decimal places beyond the third. (do not round.) Eg.: 12.878999 -> 12.878 If a double has less than 3 decimals, leave unchanged Eg.: 125 -> 125 89.24 -> 89.24 I came across this command: double example = 12.34567; double output = Math.Round(example, 3); But I do not want to round. According to the command posted above, 12.34567 -> 12.346 I want to truncate the value so that it becomes: 12

How to truncate a foreign key constrained table?

一笑奈何 提交于 2019-11-26 06:08:59
问题 Why doesn\'t a TRUNCATE on mygroup work? Even though I have ON DELETE CASCADE SET I get: ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constraint ( mytest . instance , CONSTRAINT instance_ibfk_1 FOREIGN KEY ( GroupID ) REFERENCES mytest . mygroup ( ID )) drop database mytest; create database mytest; use mytest; CREATE TABLE mygroup ( ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY ) ENGINE=InnoDB; CREATE TABLE instance ( ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, GroupID

How can I truncate a double to only two decimal places in Java? [duplicate]

拈花ヽ惹草 提交于 2019-11-26 05:30:07
问题 This question already has an answer here: How to round a number to n decimal places in Java 31 answers For example I have the variable 3.545555555, which I would want to truncate to just 3.54. 回答1: If you want that for display purposes, use java.text.DecimalFormat: new DecimalFormat("#.##").format(dblVar); If you need it for calculations, use java.lang.Math: Math.floor(value * 100) / 100; 回答2: DecimalFormat df = new DecimalFormat(fmt); df.setRoundingMode(RoundingMode.DOWN); s = df.format(d);

How do I truncate a .NET string?

假装没事ソ 提交于 2019-11-26 04:59:44
问题 I would like to truncate a string such that its length is not longer than a given value. I am writing to a database table and want to ensure that the values I write meet the constraint of the column\'s datatype. For instance, it would be nice if I could write the following: string NormalizeLength(string value, int maxLength) { return value.Substring(0, maxLength); } Unfortunately, this raises an exception because maxLength generally exceeds the boundaries of the string value . Of course, I

Truncating all tables in a Postgres database

回眸只為那壹抹淺笑 提交于 2019-11-26 02:16:28
问题 I regularly need to delete all the data from my PostgreSQL database before a rebuild. How would I do this directly in SQL? At the moment I\'ve managed to come up with a SQL statement that returns all the commands I need to execute: SELECT \'TRUNCATE TABLE \' || tablename || \';\' FROM pg_tables WHERE tableowner=\'MYUSER\'; But I can\'t see a way to execute them programmatically once I have them. 回答1: FrustratedWithFormsDesigner is correct, PL/pgSQL can do this. Here's the script: CREATE OR

How can I truncate a datetime in SQL Server?

不想你离开。 提交于 2019-11-26 01:33:09
问题 What\'s the best way to truncate a datetime value (as to remove hours minutes and seconds) in SQL Server 2008? For example: declare @SomeDate datetime = \'2009-05-28 16:30:22\' select trunc_date(@SomeDate) ----------------------- 2009-05-28 00:00:00.000 回答1: This continues to frequently gather additional votes, even several years later, and so I need to update it for modern versions of Sql Server. For Sql Server 2008 and later, it's simple: cast(getDate() As Date) Note that the last three