Sponsored Content
Full Discussion: Table Cleanup Script
Top Forums UNIX for Advanced & Expert Users Table Cleanup Script Post 302461062 by DGPickett on Friday 8th of October 2010 10:47:30 AM
Old 10-08-2010
Last I checked, truncate table does it all only for the table owner.


Quote:
Sybase Data Integration Suite 1.1 - ETL > Sybase ETL 4.2 User's Guide > Components > Destination components > DB Bulk Load Sybase IQ > Optional properties
Image Image
Chapter 6: Components
Truncate

Activate this option to remove all records from the destination table when initializing the transformation process.
Quote:
TRUNCATE statement




Deletes all rows from a table without deleting the table definition.
Image Syntax

TRUNCATE TABLE [ owner.]table-name| MATERIALIZED VIEW [ owner.]materialized-view-name
Image Remarks

The TRUNCATE statement deletes all rows from the table or materialized view.







My favorite archival delete is something like:
  1. select the delete target rows to a global temp table.
  2. bcp that table out.
  3. Verify the row and line counts match.
  4. Using a script or stored procedure or TSQL loop, for 128 lines/rows at a time in clustered index column order, delete original rows and commit.
This ensures minimal target table impact, and nothing deleted is ever noy archived, even if the unattended script has a problem.

Missing the last go & eof linefeed, second ` misplaced, misspelled table name?

Must be a code frag, fi but not if.

You are removing partial days (three days to the runtime microsecond) if your date column is a datetime type:



Maybe you want distinct, but I always say, if you think distinct, reconsider as count(*) group by.

I am not a big fan of <<, as the behavior of echo '...' is more predictable and it flows better reading left to right. I haven't quantified if a tmp file create for << is cheaper than a pipe and fork for echo, just cleaner piped stream layout. I found your second ` in the middle, when in needed to be a line below EOF.

Code:
 
#!/bin/ksh
 
echo ' CLEANUPTABLE
' >cleanup.out
 
results=$(
echo "
delete CLEANUPTABLE
where datetime_col < dateadd ('dd',-3, getdate())
go
select datetime_col, count(*) ct
from CLEANUPTABLE
group by datetime_col
go
' | isql -U${dbuid} -P${dbpwd} -S${dbsrv} -w3000 -E vi
)


Last edited by vbe; 10-08-2010 at 01:39 PM.. Reason: typo
This User Gave Thanks to DGPickett For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk/sed/ksh script to cleanup /etc/group file

Many of my servers' /etc/group file have many userid's that does not exist in /etc/passwd file and they need to be deleted. This happened due to manual manipulation of /etc/passwd files. I need to do this for 40 servers. Can anyone help me in achieving this? Even reducing a step or two will be... (6 Replies)
Discussion started by: pdtak
6 Replies

2. Shell Programming and Scripting

User Cleanup Script

Hi Guys, I've got an system setup to act as an sftp server. I have a script that allows me to create chroot users running a custom shell within their home directory, it also creates a subdirectory that they can write into. I'm trying to write a script (that I can cron at a later date) that checks... (3 Replies)
Discussion started by: King_Brucie
3 Replies

3. Shell Programming and Scripting

Cleanup script

Hi! I would like to write a script which remove some files, all beginning with the same prefix : prefix.1 doc/prefix.2 ../prefix.3 etc. So, I would create a file and chmod it executable. But I dont know how to pass a variable to a script. I would like to write something like ... (2 Replies)
Discussion started by: tipi
2 Replies

4. Shell Programming and Scripting

Suggestions/cleanup Bash script

Hello, beginner bash scripter here.. I was able to write a script and it works just fine. I'm just wondering if someone could chime in or any suggestions to make it cleaner or tighter so to speak. I have a disk to disk backup solution which uses 250GB disks. When one gets full I just po in a new... (7 Replies)
Discussion started by: woodson2
7 Replies

5. Shell Programming and Scripting

Mail cleanup from ksh script, keeping 50 most recent msgs

I found some posts describing how to completely clean out a mailbox in Unix/Linux. But I want to keep the 50 most recent messages. Any ideas out there? Thanks! (3 Replies)
Discussion started by: OPTIMUS_prime
3 Replies

6. Shell Programming and Scripting

pid.cleanup script.

Hi guys! I have a directory in the production environment from which i have to delete files older then 40 minutes with .pid extention. I wrote a script below for the purpose. #!/bin/bash # # Script to delete specific file older than N minutes. # OLDERTHAN="40" #40 minutes ... (6 Replies)
Discussion started by: sajid.shah
6 Replies

7. UNIX for Dummies Questions & Answers

Creating a condensed table from a pre-existing table in putty

Hello, I'm working with putty on Windows 7 professional and I'd like to know if there's a way to gather specific lines from a pre-existing table and make a new table with that information. More specifically, I'd like the program to look at a specific column, say column N, and see if any of the... (5 Replies)
Discussion started by: Deedee393
5 Replies

8. Shell Programming and Scripting

Suggestion with script to cleanup

I need help with sed and awk scripts to search for Symmetrix ID=000090009902 and then grep its child disk devices associated to the dead paths and display them only, so that those dead devices can be removed. test01:/#powermt display dev=all Pseudo name=hdiskpower0 Symmetrix ID=000090009902... (0 Replies)
Discussion started by: aix_admin_007
0 Replies

9. Shell Programming and Scripting

UNIX script for cleanup

Hello, I need some help from unix guru's here..I am looking for some advanced level script to cleanup the directories and files from specific directories under a file system.. The folders are created under /opt/modules And under modules, there are multiple subfolders with the application... (6 Replies)
Discussion started by: mb525
6 Replies

10. Web Development

Getting Rid of Annoying Bootstrap Table Borders and Wayward Table Lines

Bootstrap is great; but we have had some issues with Bootstrapped <tables> (and legacy <fieldset> elements) showing annoying, wayward lines. I solved that problem today with this simple jQuery in the footer: <script> $(function(){ $('tr, td, fieldset,... (0 Replies)
Discussion started by: Neo
0 Replies
All times are GMT -4. The time now is 07:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy