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
9
votes
3 answers

How to Truncate Table using CakePHP?

I want to truncate my Database Table, with CakePHP Model, I have used $this->Model->deleteAll code for the same, and it works fine. Now, What i want is, next time whenever my new records are inserting, it should start ID with 1 only, which does not…
Aditya P Bhatt
  • 21,431
  • 18
  • 85
  • 104
9
votes
4 answers

Should a cast be used to truncate a long variable?

I have a 16 bits unsigned variable. I need to split it in 8 bits chunks. Is doing the following enough: chunk_lsb = (uint8)variable; chunk_msb = (uint8)(variable >> 8); Or should I use a mask: chunk_lsb = (uint8)(variable & 0xFFu); chunk_msb =…
Soyding Mete
  • 137
  • 8
9
votes
9 answers

Vue : Limit characters in text area input, truncate filter?

I tried creating a custom filter : filters: { truncate(text, stop, clamp) { return text.slice(0, stop) + (stop < text.length ?…
J W
  • 165
  • 1
  • 1
  • 6
9
votes
2 answers

RODBC and Microsoft SQL Server: Truncating Long Character Strings

I am trying to query a variable from a Microsoft SQL Server database using R/RODBC. RODBC is truncating the character string at 8000 characters. Original code: truncates at 255 characters (as per RODBC documentation) library(RODBC) con_string <-…
Chris
  • 3,401
  • 5
  • 33
  • 42
9
votes
1 answer

Truncate DynamoDb or rewrite data via Data Pipeline

There is possibility to dump DynamoDb via Data Pipeline and also import data in DynamoDb. Import is going well, but all the time data appends to already exists data in DynamoDb. For now I found work examples that scan DynamoDb and delete items one…
9
votes
4 answers

How to reset Sql Server 2008 database?

I want to reset my sql server 2008 database like when it's first created. all the identities must be reset. All the data in the database must be gone. Is there a way to do this?
ward87
  • 3,026
  • 7
  • 27
  • 27
9
votes
12 answers

Truncating Strings by Bytes

I create the following for truncating a string in java to a new string with a given number of bytes. String truncatedValue = ""; String currentValue = string; int pivotIndex = (int) Math.round(((double) string.length())/2); …
stevebot
  • 23,275
  • 29
  • 119
  • 181
9
votes
1 answer

Is There A Way to Truncate by Words in View in Django?

I made a JSON serializer to view. I returned a QuerySet object which is called entries which looks for POST argument as below: entries = blog.models.Entry.objects.filter(content__icontains=request.POST.get('q')) Then I used serializers from…
Eray Erdin
  • 2,633
  • 1
  • 32
  • 66
9
votes
7 answers

SQL Query to truncate table in IBM DB2

Can any one give me the syntax to truncate a table in IBM DB2. I m running the following command: truncate table tableName immediate; The eror is DB2 SQLCODE=-104, SQLSTATE=42601, SQLERRMC=table;truncate ;JOIN , DRIVER=3.50.152 Message: An…
Cshah
  • 5,612
  • 10
  • 33
  • 37
9
votes
3 answers

Postgres: Reduce varchar size and truncate

I currently have a Postgres 8.4 database that contains a varchar(10000) column. I'd like to change this into a varchar(255) and truncate any data that happens to be too long. How can I do this?
William Jones
  • 18,089
  • 17
  • 63
  • 98
9
votes
6 answers

Truncate a UTF-8 string to fit a given byte count in PHP

Say we have a UTF-8 string $s and we need to shorten it so it can be stored in N bytes. Blindly truncating it to N bytes could mess it up. But decoding it to find the character boundaries is a drag. Is there a tidy way? [Edit 20100414] In addition…
user213154
9
votes
6 answers

Bulk delete (truncate vs delete)

We have a table with a 150+ million records. We need to clear/delete all rows. Delete operation would take forever due to it writing to the t-logs and we cannot change our recovery model for the whole DB. We have tested the truncate table option.…
Paulin Shah
  • 91
  • 1
  • 2
9
votes
6 answers

How to limit text string in Eval

I have a hyperlink with the navigate property set like this: NavigateUrl='<%# Eval("My Text") %>' How can I limit the string to 140 characters ? I have tried this Eval("My Text").ToString().Substring(0,140) but if the string length is less…
Mario
  • 13,941
  • 20
  • 54
  • 110
8
votes
2 answers

Truncate DateTime in NHibernate QueryOver SelectGroup

I have a fairly run-of-the-mill QueryOver query containing the following, .SelectList(list => list .SelectGroup(() => txn.GroupField) .SelectGroup(() => txn.Date)) .List() This query works as expected however I now have a…
John
  • 605
  • 2
  • 7
  • 17
8
votes
4 answers

How to truncate a partitioned external table in hive?

I'm planning to truncate the hive external table which has one partition. So, I have used the following command to truncate the table : hive> truncate table abc; But, it is throwing me an error stating : Cannot truncate non-managed table abc. Can…
fervent
  • 123
  • 1
  • 2
  • 10