truncate

Truncate Table Within Transaction

不羁的心 提交于 2019-11-28 06:41:20
Can the SQL "truncate table" command be used within a transaction? I am creating an app and my table has a ton of records. I want to delete all the records, but if the app fails I was to rollback my transaction. Deleting each record takes a very long time. I'm wondering if I use truncate table, can I still rollback the transaction and get my data back in the event of a failure. I realize that truncate table doesn't write each delete to the transaction log, but I'm wondering if it writes the page deallocation to the log so that rollback works. In SQL Server, you can rollback a TRUNCATE from a

PHP & MySQL: Truncate multiple tables

故事扮演 提交于 2019-11-28 05:54:29
问题 I tried to truncate a table but why is it not working? must something wrong in the database query? $sql = "TRUNCATE TABLE `table_name`"; $result = $connection -> query($sql); Ideally, I want to truncate all tables in one go - is it possible? if you wonder what is inside the class that I use to make the database queries, here is it, #connects the database and handling the result class __database { protected $connection = null; protected $error = null; #make a connection public function _

remove All lines except first 20 using php

喜欢而已 提交于 2019-11-28 05:28:05
问题 how to remove every line except the first 20 using php from a text file? 回答1: For a memory efficient solution you can use $file = new SplFileObject('/path/to/file.txt', 'a+'); $file->seek(19); // zero-based, hence 19 is line 20 $file->ftruncate($file->ftell()); 回答2: If loading the entire file in memory is feasible you can do: // read the file in an array. $file = file($filename); // slice first 20 elements. $file = array_slice($file,0,20); // write back to file after joining. file_put

Pros & Cons of TRUNCATE vs DELETE FROM

无人久伴 提交于 2019-11-28 04:49:16
Could someone give me a quick overview of the pros and cons of using the following two statements: TRUNCATE TABLE dbo.MyTable vs DELETE FROM dbo.MyTable It seems like they both do the same thing when all is said and done; but are there must be differences between the two. dcp TRUNCATE doesn't generate any rollback data, which makes it lightning fast. It just deallocates the data pages used by the table. However, if you are in a transaction and want the ability to "undo" this delete, you need to use DELETE FROM , which gives the ability to rollback. EDIT: Note that the above is incorrect for

What is the command to truncate a SQL Server log file?

拈花ヽ惹草 提交于 2019-11-28 02:36:09
I need to empty an LDF file before sending to a colleague. How do I force SQL Server to truncate the log? if I remember well... in query analyzer or equivalent: BACKUP LOG databasename WITH TRUNCATE_ONLY DBCC SHRINKFILE ( databasename_Log, 1) Blorgbeard In management studio: Don't do this on a live environment, but to ensure you shrink your dev db as much as you can: Right-click the database, choose Properties , then Options . Make sure "Recovery model" is set to "Simple", not "Full" Click OK Right-click the database again, choose Tasks -> Shrink -> Files Change file type to "Log" Click OK.

Truncated Data when Importing from Excel to an Access Memo Field

邮差的信 提交于 2019-11-27 23:09:25
Access is truncating the data in a couple Memo fields when I am appending an Excel file. The field in the Access table is already set as a Memo type. I believe the problem is that I do not have any entries in the first few rows of some of the memo fields. Access is assuming the data is a text field, even though I have already set it as a Memo type. I have tried appending as a CSV. Did not work. I have put dummy data in the first row that exceeds the 255 character limit and the data is not truncated if I do that. I do not want to have to put dummy data in every time I have to import an Excel

Memory-efficient way to truncate large array in Matlab

感情迁移 提交于 2019-11-27 21:21:35
I have a large (multi-GB) array in Matlab, that I want to truncate¹. Naively, I thought that truncating can't need much memory, but then I realised that it probably can: >> Z = zeros(628000000, 1, 'single'); >> Z(364000000:end) = []; Out of memory. Type HELP MEMORY for your options. Unless Matlab does some clever optimisations, before truncating Z , this code actually creates an array (of type double!) 364000000:628000000 . I don't need this array, so I can do instead: >> Z = Z(1:363999999); In this case, the second example works, and is fine for my purpose. But why does it work? If Z

Mysql truncates concatenated result of a GROUP_CONCAT Function

筅森魡賤 提交于 2019-11-27 19:59:33
I've created a view which uses GROUP_CONCAT to concatenate results from a query on products column with data type of 'varchar(7) utf8_general_ci' in a column named concat_products . The problem is that mysql truncates value of concat_products column. phpMyAdmin says the data type of concat_products column is varchar(341) utf8_bin table products: CREATE TABLE `products`( `productId` tinyint(2) unsigned NOT NULL AUTO_INCREMENT, `product` varchar(7) COLLATE utf8_general_ci NOT NULL, `price` mediumint(5) unsigned NOT NULL, PRIMARY KEY (`productId`)) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET

Truncating a file while it's being used (Linux)

ⅰ亾dé卋堺 提交于 2019-11-27 19:18:52
I have a process that's writing a lot of data to stdout, which I'm redirecting to a log file. I'd like to limit the size of the file by occasionally copying the current file to a new name and truncating it. My usual techniques of truncating a file, like cp /dev/null file don't work, presumably because the process is using it. Is there some way I can truncate the file? Or delete it and somehow associate the process' stdout with a new file? FWIW, it's a third party product that I can't modify to change its logging model. EDIT redirecting over the file seems to have the same issue as the copy

Truncate a float and a double in java

一曲冷凌霜 提交于 2019-11-27 16:33:29
问题 I want to truncate a float and a double value in java. Following are my requirements: 1. if i have 12.49688f, it should be printed as 12.49 without rounding off 2. if it is 12.456 in double, it should be printed as 12.45 without rounding off 3. In any case if the value is like 12.0, it should be printed as 12 only. condition 3 is to be always kept in mind.It should be concurrent with truncating logic. 回答1: try this out- DecimalFormat df = new DecimalFormat("##.##"); df.setRoundingMode