Questions tagged [truncate]

Data truncation is the automatic or deliberate shortening of data. A string, decimal number, or datestamp can be truncated to a shorter value. A data stream (such as a file or record set) can be truncated when either the entirety of the data is not needed or when it will be stored in a location too short to hold its entire length. No rounding occurs when numbers are truncated.

Data truncation may occur automatically, such as when a long string is written to a smaller buffer, or deliberately, when only a portion of the data is wanted. The truncation principles can be used in several different ways.

###Function Calls

Many data handling programs have built in methods or functions to handle truncation. Syntax will vary, but the principles are the same. Examples include:

  • Strings: TRUNC("This is a string.", 12) = This is a st
  • Decimals: TRUNC(3.14159, 2) = 3.14 or floor(3.14159) = 3
  • Dates: TRUNC(#7/4/2017 23:45#) = #7/4/2017 00:00#

###SQL Statement

In SQL, the TRUNCATE TABLE statement removes all rows from a table without invoking any triggered actions. The result of this operation quickly removes all data from a table, typically bypassing a number of integrity enforcing mechanisms. It was officially introduced in the SQL:2008 standard. In the SQL standard TRUNCATE TABLE is defined as a data manipulation language (DML) feature but database vendors often classify it as DDL for their own implementation-specific reasons.

The TRUNCATE TABLE mytable statement is logically (though not physically) equivalent to the DELETE FROM mytable statement (without a WHERE clause).

Datestamp values

Datestamps can be truncated. 2009-02-09 09:41:22 can be truncated, for example, to the:

  • year 2009-01-01 00:00:00
  • month 2009-02-01 00:00:00
  • day 2009-02-09 00:00:00
  • hour 2009-02-09 09:00:00

Related tags

References

Function Calls

SQL Statements

1585 questions
0
votes
2 answers

Split a file in several output

I am trying to divide a big file into different files containing single information for each variable inside the file. my input file look like this: #CHROM POS ID REF ALT QUAL FILTER INFO FORMAT PID008SM ...info here…
0
votes
1 answer

Truncate or Delete tables from the MySql database

I have a databse called store having 100 tables having too much foreign key references with tables, having thousands of records. Problem: Is it possible something like truncate to delete all the rows of all the tables in a single query. I tried but…
subodh
  • 6,136
  • 12
  • 51
  • 73
0
votes
2 answers

SQL rounding and truncation, needs a thorough explanation

I'm a novice when it comes to SQL and PHP, and I'm trying to round an average price result and take off the extra zeroes that currently appear. Currently my result turns up as: $3.005000 My code currently reads as follows: $result =…
user194140
0
votes
1 answer

SQL Server: About improving diskspace

I've tried to find out the answer to this question, but i haven't found a clear and/or precise answer. In MS SQL (2008 in this case) does any of this commands: Delete, Truncate or Drop (table), "automatically" sets free the amount of disk space that…
0
votes
1 answer

Securing data by truncating / adding bytes at runtin

I do have an android application that downloads PDF files for display in a magazine app. To secure the data I am already setting a user password. I was additionally thinking of removing the last 100 bytes of each file when stored on the device and…
idplanter
  • 160
  • 2
  • 9
0
votes
1 answer

How do I truncate all data in my MySQL database?

I'm using MySql 5.5 on Mac 10.7.5. From the shell (I'm using bash), I'd like to be able to run a command o truncate data in all tables. Also, I'd like to enter a single command that won't prompt me for a password. I've tried this, that I found on…
Dave
  • 15,639
  • 133
  • 442
  • 830
0
votes
2 answers

mysql insert nested select from other db truncates double values

I have a table in one database, call this db x. I have another database, call it y. I want to copy data from x.some_table to y.some_table. I don't want to do an exact copy of the table, because some columns don't make sense in database b. I use the…
San Jacinto
  • 8,774
  • 5
  • 43
  • 58
0
votes
1 answer

When casting float to int, why do numbers > -1 and < -0.5 go to -1, and numbers >= -0.5 and < 0 go to 0?

I always thought when floats get truncated to ints, it always becomes the highest number smaller than the float. However, when the float is between -0.5 and 0, it gets converted to 0 instead of -1! Why is this? Is this language-specific? I am seeing…
Popcorn
  • 5,188
  • 12
  • 54
  • 87
0
votes
1 answer

Sitecore Analytics truncation

We have implemented Sitecore for our future site. We are going live soon with our corporate site. We had some testing done on this site to make sure everything was working right. There is some data that was written to the Analytics database due to…
Gabbar
  • 4,006
  • 7
  • 41
  • 78
0
votes
1 answer

mysql Truncate table vs delete

We are about to deploy some code that truncates tables in our mysql 4 database. We are doing this to get around some replication 'weirdness' that we are seeing (and is widely known) with temp tables. My knee-jerk reaction when I saw this in a code…
joeslice
  • 3,454
  • 1
  • 19
  • 24
0
votes
2 answers

Truncate double or add extra 0 to the decimal - Java

This might be a duplicate, but I cannot find any answers that work with my code. I'm trying to truncate my results for a method(for calculating a fee) in Java. I then try to write the results to a text file, but it's not showing like it should. This…
B.B10
  • 171
  • 1
  • 7
  • 16
0
votes
1 answer

Extracting parts of words from a file

I have a list, "list A," containing tens of thousands of entries (4 example entries shown below). I'd like to create from "list A" another list, "list B." I need each entry of "list B" to contain only the 1st 4 (out of 5) characters of the 1st…
0
votes
1 answer

how to get string that fits to a constrained size such as UILabel

I have a very very long text, so instead of using UITextView, I want to truncate the text to small chunks that can fit to a label with width and height 300, 400, and based on number of chunks, I want to create UILabel dynamically and populate them…
Hashem Aboonajmi
  • 13,077
  • 8
  • 66
  • 75
0
votes
1 answer

DBD::MySQL: How do I take the "LongReadLen" to the functioning?

How to I have to change this script to get the BLOB output truncated? #!/usr/bin/env perl use warnings; use strict; use utf8; use 5.10.1; use DBI; my $user = 'username'; my $passwd = 'password'; my $db = 'information_schema'; my $dbh =…
sid_com
  • 24,137
  • 26
  • 96
  • 187
0
votes
2 answers

DBD::MySQL: LongReadLen and LongTruncOk

Have the attributes LongReadLen and LongTruncOk when using DBD::mysql as driver for the Perl5 Database Interface (DBI) any meaning? I didn't found these attributes in the DBD::mysql documentation but I found some example on the internet which uses…
sid_com
  • 24,137
  • 26
  • 96
  • 187