Batch script to delete records
I have an Oracle 10 DB that I am "in charge of", however, there are other gov't DBAs that actually control it. I am working with a tool that was developed by the previous contract winner and they are no help. The tool I use allows for records to be created, and for the most part, edited. However, there is no way to back out something if you make a mistake. I was told by the gov't DBA to create a batch script with exactly the records I want deleted and he'd run it. There are 16 tables and the criteria is the same for each; a specific date, and userID is the same for each record....
DELETE FROM Table1 WHERE DATE = '01-24-2014' and USERID = 'Me'; I need to do that 16 times and only change the table name. I haven't written a script in 15 years and old age is messing with me. Anyone have a suggestion? Thank you in advance.
The commit is worrisome; I'd want someone to watch and be sure each statement comes back with the expected number of rows before committing.
Ahh - yet another reminder of the old 'desktop computing' era.
Using Paradox:
1. a DELETE query would not only delete the rows but would create a table named 'DELETED' that actually contained the rows that were deleted. Then you could examine them and even put them back with an INSERT if you wanted.
2. an UPDATE query would perform the update and create a table named 'UPDATED' containing the original rows.
3. an INSERT query would insert and also create a table name 'INSERTED' containing a copy of the rows inserted.
I was always looking for Oracle to implement a CTAD - 'create table as delete' to make it easier to implement auditing and controls.
Similar Messages
-
As i am fresher Please share the doc of ECMA script using java script in SharePoint 2013 step by step also how we can insert,update,delete records in list using ECMA script.
Thanks and Regards, Rangnath MaliHi,
According to your post, my understanding is that you want to use JavaScript to work with SharePoint list.
To create list items, we can create a ListItemCreationInformation object, set its properties, and pass it as parameter to the addItem(parameters) function
of the List object.
To set list item properties, we can use a column indexer to make an assignment, and call the update() function so that changes will take effect when you callexecuteQueryAsync(succeededCallback,
failedCallback).
And to delete a list item, call the deleteObject() function on the object.
There is an MSDN article about the details steps of this topic, you can have a look at it.
How to: Create, Update, and Delete List Items Using JavaScript
Thanks & Regards,
Jason
Jason Guo
TechNet Community Support -
Script to Delete more than 1 user from the database
Hi All,
I have a list of users in a file and i want to write a script to delete all these
users from my database.
I have tried deleting users using:
drop user user1,user2,user3..... but it doesn't seem to work.
Can anyone suggest how do i read the users from the file and delete them one by oneYou can use an external table :
SYS@db102 SQL> select username from all_users
2 where username like 'USER%';
USERNAME
USER1
USER2
USER3
SYS@db102 SQL> !cat users_to_drop.txt
USER1
USER2
USER3
SYS@db102 SQL> create table test.users_to_drop
2 (
3 userx char(30)
4 )
5 organization external
6 ( type oracle_loader
7 default directory work
8 access parameters
9 ( records delimited by newline
10 )
11 location ('users_to_drop.txt')
12 )
SYS@db102 SQL> /
Table created.
SYS@db102 SQL> begin
2 for U in (select userx from test.users_to_drop) loop
3 dbms_output.put_line('Dropping '||U.userx);
4 execute immediate 'drop user '||U.userx||' cascade';
5 end loop;
6 end;
SYS@db102 SQL> /
Dropping USER1
Dropping USER2
Dropping USER3
PL/SQL procedure successfully completed.
SYS@db102 SQL> select username from all_users
2 where username like 'USER%';
no rows selected
SYS@db102 SQL> -
Error while deleting Records using ROWID
Hi all
I have a small PL/SQL Block which accepts the Table Name as the User Input and
deletes duplicate records from that table using ROWID.
SET SERVEROUTPUT ON
SET VERIFY OFF
PROMPT Script to Delete Duplicate Records from a Table using ROWID
ACCEPT TAB_NAME PROMPT 'Enter the Table Name : '
DECLARE
v_tab_name VARCHAR2(50):='&TAB_NAME';
BEGIN
EXECUTE IMMEDIATE 'DELETE FROM v_tab_name AA WHERE AA.ROWID <> (SELECT MIN(B.ROWID) FROM v_tab_name B WHERE AA.ID=B.ID)';
DBMS_OUTPUT.PUT_LINE('Duplicate Records Deleted');
END;
When i execute this query it errors out saying table or view does not exist.
Anybody's help is kindly appreciated.
Regards
Nakul.VDear Nakul.V!
Please change your execute immediate statement as follows:
EXECUTE IMMEDIATE 'DELETE FROM ' || v_tab_name || ' AA
WHERE AA.ROWID IN (SELECT MIN(B.ROWID)
FROM' || v_tab_name || ' B
WHERE AA.ID=B.ID)';Yours sincerely
Florian W. -
[DW MX 2004] DELETE RECORD
Hi,
I can't DELETE RECORD in LOCAL SERVER (MySQL Server 5.0)
and REMOTE SERVER , but INSERT AND UPDATE WORKS.
Page code is
<?php require_once('../Connections/connpuntofermo.php');
?>
<?php
session_start();
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";
// *** Restrict Access To Page: Grant or deny access to this
page
function isAuthorized($strUsers, $strGroups, $UserName,
$UserGroup) {
// For security, start by assuming the visitor is NOT
authorized.
$isValid = False;
// When a visitor has logged into this site, the Session
variable
MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that
Session
variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only
certain
users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
// Or, you may restrict access to only certain users based
on their
username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
if (($strUsers == "") && true) {
$isValid = true;
return $isValid;
$MM_restrictGoTo = "index.php";
if (!((isset($_SESSION['MM_Username'])) &&
(isAuthorized("",$MM_authorizedUsers,
$_SESSION['MM_Username'],
$_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($QUERY_STRING) && strlen($QUERY_STRING)
> 0)
$MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar .
"accesscheck=" .
urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
?>
<?php
function GetSQLValueString($theValue, $theType,
$theDefinedValue = "",
$theNotDefinedValue = "")
$theValue = (!get_magic_quotes_gpc()) ?
addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" :
"NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) .
"NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" :
"NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue :
$theNotDefinedValue;
break;
return $theValue;
if ((isset($_GET['ID'])) && ($_GET['ID'] != "")) {
$deleteSQL = sprintf("DELETE FROM news WHERE ID=%s",
GetSQLValueString($_GET['ID'], "int"));
mysql_select_db($database_connpuntofermo, $connpuntofermo);
$Result1 = mysql_query($deleteSQL, $connpuntofermo) or
die(mysql_error());
$deleteGoTo = "ok-cancella.php";
if (isset($_SERVER['QUERY_STRING'])) {
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
header(sprintf("Location: %s", $deleteGoTo));
mysql_select_db($database_connpuntofermo, $connpuntofermo);
$query_rs_elenco = "SELECT ID, `data`, titolo FROM news ORDER
BY ID DESC";
$rs_elenco = mysql_query($query_rs_elenco, $connpuntofermo)
or
die(mysql_error());
$row_rs_elenco = mysql_fetch_assoc($rs_elenco);
$totalRows_rs_elenco = mysql_num_rows($rs_elenco);
?>
<html><!-- InstanceBegin
template="/Templates/template-adm.dwt"
codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>amministrazione Piadineria Punto
Fermo</title>
<!-- InstanceEndEditable --><meta
http-equiv="Content-Type"
content="text/html; charset=iso-8859-1"><style
type="text/css">
<!--
body {
background-color: #CCD57B;
margin-bottom: 0px;
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
-->
</style>
<link href="../css/style.css" rel="stylesheet"
type="text/css">
<style type="text/css">
@import "news/domnews.css";
</style>
<script type="text/javascript"
src="news/domnews.js"></script>
<!-- InstanceBeginEditable name="head" --><!--
InstanceEndEditable -->
</head>
<body>
<table width="100%" height="100%" border="0"
align="center" cellpadding="0"
cellspacing="0">
<tr>
<td align="center" valign="middle"><table
width="760" height="430"
border="0" align="center" cellpadding="0" cellspacing="1"
bgcolor="#A7B339">
<tr>
<td width="779" align="left" valign="middle"
bgcolor="#FFFFCC"><table width="760" height="334"
border="0" cellpadding="0"
cellspacing="0">
<tr>
<td align="center"
class="body"><strong>AMMINISTRAZIONE SITO
PUNTO FERMO </strong></td>
</tr>
<tr>
<!-- InstanceBeginEditable name="header" --><td
height="42"
align="center" valign="top" class="body"><a
href="menu.php"
class="body">torna
a menù principale </a></td>
<!-- InstanceEndEditable --> </tr>
<tr>
<!-- InstanceBeginEditable name="body" -->
<td align="center" valign="top"
class="body"><p>ELENCO NEWS
INSERITE</p>
<table width="505" border="0" cellpadding="5"
cellspacing="1"
bgcolor="#999999" class="body">
<tr bgcolor="#FFFFA8">
<td>ID</td>
<td width="104">DATA</td>
<td width="134">TITOLO</td>
<td width="110"> </td>
<td width="112"> </td>
</tr>
<?php do { ?>
<tr align="left" valign="top" bgcolor="#FFFFCC">
<td><?php echo $row_rs_elenco['ID'];
?></td>
<td><?php echo $row_rs_elenco['data'];
?></td>
<td><?php echo $row_rs_elenco['titolo'];
?></td>
<td><a href="mod-news.php?ID=<?php echo
$row_rs_elenco['ID']; ?>"
class="body">MODIFICA</a></td>
<td><form name="elimina1" method="post"
action="">
<input type="submit" name="Submit" value="ELIMINA">
</form></td>
</tr>
<?php } while ($row_rs_elenco =
mysql_fetch_assoc($rs_elenco)); ?>
</table>
<p> </p></td>
<!-- InstanceEndEditable --> </tr>
<tr>
<td> </td>
</tr>
</table></td>
</tr>
</table> </td>
</tr>
</table>
</body>
<!-- InstanceEnd --></html>
<?php
mysql_free_result($rs_elenco);
?>
Where is error?
Thanks.MX 2004 was always a bit "gummy" on this. Instead of using the DW wizard, I downloaded a free version of Microsoft SQL Server Express Edition. I use that for all table Inserts, Updates,etc. This accesses the tables directly on the server. Nothing needs to be synced, put, gotten or whatever. Use DW for Form and UI creation and making prebuilt queries.
Hope that helps
Jerry H -
Deleting records - mySQL / PHP
I've just worked through this whole database thing from
scratch again after a little glitch, and it's all working pretty
well.
I do still have the issue with deleting records - I have the
search results page which is fine, and has a delete options at the
end of the row.
It was working just fine bringing up the 'confirm deletion'
page with the selected record - but it goes wrong after I add the
'delete record' server behaviour.
Basically after I do, when I click delete in the results
page, it skips the 'confirm deletion' page, going straight to the
'deletion confirmed' page.
It does still delete the record at least, but it would be
good to have the confirmation page.
Here's a
link
(if you need to log in use 'admin' and 'password'.)
This is all the script code in the 'confirm delete' page :
<?php require_once('../Connections/ConnHandprint.php');
?>
<?php
function GetSQLValueString($theValue, $theType,
$theDefinedValue = "", $theNotDefinedValue = "")
$theValue = (!get_magic_quotes_gpc()) ?
addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" :
"NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) .
"'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" :
"NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue :
$theNotDefinedValue;
break;
return $theValue;
if ((isset($_GET['recordID'])) && ($_GET['recordID']
!= "")) {
$deleteSQL = sprintf("DELETE FROM Contacts WHERE
ContactID=%s",
GetSQLValueString($_GET['recordID'], "int"));
mysql_select_db($database_ConnHandprint, $ConnHandprint);
$Result1 = mysql_query($deleteSQL, $ConnHandprint) or
die(mysql_error());
$deleteGoTo = "contactdeleted.php";
if (isset($_SERVER['QUERY_STRING'])) {
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
header(sprintf("Location: %s", $deleteGoTo));
$colname_Recordset1 = "1";
if (isset($_GET['recordID'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ?
$_GET['recordID'] : addslashes($_GET['recordID']);
mysql_select_db($database_ConnHandprint, $ConnHandprint);
$query_Recordset1 = sprintf("SELECT * FROM Contacts WHERE
ContactID = %s", $colname_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $ConnHandprint)
or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
Any ideas?
Cheers,
IainHi,
It is a good idea to do it in database level such that declare foreign key from child to parent table and specify DELETE CASCADE.
regards,
' -
Delete record behaviour (PHP/mySQL)
I've just worked through this whole database thing from
scratch again after a little glitch, and it's all working pretty
well.
I do still have the issue with deleting records - I have the
search results page which is fine, and has a delete options at the
end of the row.
It was working just fine bringing up the 'confirm deletion'
page with the selected record - but it goes wrong after I add the
'delete record' server behaviour.
Basically after I do, when I click delete in the results
page, it skips the 'confirm deletion' page, going straight to the
'deletion confirmed' page. It's as tho' simply going to the
confirmation page is triggering the deletion, rather than requiring
the 'delete record' button to be pressed. Does the form / button
require an 'action'? Although as far as I can tell I followed the
instructions
correctly, but something is going wrong on the confirmation page.
It does still delete the record at least, but it would be
good to have the confirmation page.
Here's a link (if you need to log in use 'admin' and
'password'.)
link
This is all the script code in the 'confirm delete' page :
<?php require_once('../Connections/ConnHandprint.php');
?>
<?php
function GetSQLValueString($theValue, $theType,
$theDefinedValue = "", $theNotDefinedValue = "")
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue)
: $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" :
"NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) .
"'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" :
"NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue :
$theNotDefinedValue;
break;
return $theValue;
if ((isset($_GET['recordID'])) && ($_GET['recordID']
!= "")) {
$deleteSQL = sprintf("DELETE FROM Contacts WHERE
ContactID=%s",
GetSQLValueString($_GET['recordID'], "int"));
mysql_select_db($database_ConnHandprint, $ConnHandprint);
$Result1 = mysql_query($deleteSQL, $ConnHandprint) or
die(mysql_error());
$deleteGoTo = "contactdeleted.php";
if (isset($_SERVER['QUERY_STRING'])) {
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
header(sprintf("Location: %s", $deleteGoTo));
$colname_Recordset1 = "1";
if (isset($_GET['recordID'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ?
$_GET['recordID'] : addslashes($_GET['recordID']);
mysql_select_db($database_ConnHandprint, $ConnHandprint);
$query_Recordset1 = sprintf("SELECT * FROM Contacts WHERE
ContactID = %s", $colname_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $ConnHandprint)
or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
Any ideas?
CheersHello,
S. Khawar wrote:
my question is that when I execute DELETE_RECORD built in it fails due to constraint restriction and Oracle forms raise message that "Child record exist/unable to delete record " until here it's Ok but Oracle Forms still removes record from the screen/form and move up the remaining records(although record is failed to delete).Yet this is the default forms behaviour. Because when you press delete it will remove from the screen but not from the database till you use COMMIT as francois mentioned.
I want the Oracle Form to do not remove record from screen/form once it's failed to delete record actually.Yes, for this type of requirement. Why don't you check dependency of record before removing the record. What i mean is you can use the code in KEY-DELREC trigger like below (before using the DELETE_RECORD built-in) for checking if child record exists then show message otherwise remove. For example...
DECLARE
vCntRec NUMBER;
BEGIN
SELECT COUNT(*)
INTO vCntRec
FROM child_table_name
WHERE key_column = :form_key_column_name;
IF vCntRec>0 THEN -- Here means record found in child table so it will not remove from screen but message will appear.
MESSAGE('<Your error message goes here...>');
MESSAGE('<Your error message goes here...>');
RAISE FORM_TRIGGER_FAILURE;
ELSE -- Here mean there is not dependency so it will remove which is default forms behaviour.
DELETE_RECORD;
END IF;
END;So, when you will press button for delete first it will check for any child record if exsits then it will display message and will not vanish from the screen otherwise it will remove from the screen and furthor COMMIT will remove from database.
-Ammad
Edited by: Ammad Ahmed on Jul 7, 2010 8:48 AM -
Sql*loader in batch script
Hi,
I am calling a sqlloader and a procedure within a loop inside a batch script.
Sometimes, The sqlloader fails and subsequent procedure fails, I am not able move to the next iteration.
How to catch oracle errors in batch script
Thx.hi,
My batch script is something like this.
I want to catch errors when
1. sql*loader throws error
2. when my pl/sql throws error.
I welcome any suggestions to improve this code.
d:
echo cd Data\Scripts
for %%f in (D:\Data\DELIVERY_NOTE\*.csv) Do (
echo conn config/config;
echo delete from SQLLOAD_DELIVERY_STAGE;
)| sqlplus -s /nolog
sqlldr USERID=config/config control=D:\Data\Scripts\loaddata_del.ctl skip=2 data=%%f
echo conn config/config;
echo exec DELIVERY_NOTE_PKG.Populate_Del_Note_stage;
echo exec DELIVERY_NOTE_PKG.PROCESS_DELIVERY_NOTE;
)| sqlplus -s /nolog
move %%f D:\Data\Processed_Delivery\
cd D:\Data\processed_Delivery\
rename *.csv *.csv.processed
cd d:\Data\scripts\
echo #############
echo PROCESSED THE FILE %%f AT %data% %time%
echo ############
) -
How to extract row_id from PL/SQL procedure and assign that to batch script
Hello Team,
I am stuck with a requirement, wherein I am running a batch script and within the batch script I am calling a procedure which inserts a record in a table (Including a column named l_id).
I need this generated l_id to be passed on as a variable to batch script after PL/SQL procedure completion. So that I can refer this same l_id to update the same record in the table again in the same batch script in the later part.
Looking for some suggestions!!!!
Thanks
-Vj.789153 wrote:
I am stuck with a requirement, wherein I am running a batch script and within the batch script I am calling a procedure which inserts a record in a table (Including a column named l_id). Operating system? Scripting language or command shell used?
I need this generated l_id to be passed on as a variable to batch script after PL/SQL procedure completion. So that I can refer this same l_id to update the same record in the table again in the same batch script in the later part.
Looking for some suggestions!!!!Don't do this using batch scripts. Batch scripts are very much inferior compared to stored PL/SQL code when it comes to managing databases processes and performing data crunching.
Why can't this be written entirely in PL/SQL? And execution managed from either DBMS_JOB or DBMS_SCHEDULER ? And before answering that, consider the following:
- what is the superior language, PL/SQL or shell script?
- what provides tighter integration with the database, PL/SQL or shell script?
- what provides proper security and access control, PL/SQL or shell script?
As you can call SQL*Plus from a shell script to run PL/SQL, you can call a shell script from PL/SQL instead to run external commands and processes.
Use the right tool for the job. And shell scripting is an excellent tool - but only when correctly used. Are you using it correctly? I strongly doubt that... -
Alert Button for delete record ASP
Hello I have a delete record and have added a javascript
alert box. I have 2 options. The first is OK and the second is to
cancel. The problem is that I having trouble with the cancel part.
It deletes the record regardless. I tried to pass information such
as if they click cancel <% TH_Proceed = "" %> and in the
delete Dreamweaver code put an if statement to see if the
TH_Proceed <> "" to proceed.
It seems like once it is clicked the information from the
form to delete is passed and it forgets about what I try to send.
Sorry I am not to experienced with this.
Thanks for any help<form, not </form
onSubmit = "return confirm_entry()"
If you don't return anything from the function call, the
submit will of
course go through since that's the default behavior.
The function itself must be altered, too. After your alert
saying the file
will be deleted, return true. After your alert saying the
file will not be
deleted, return false.
"Pixel Pusher" <[email protected]> wrote in
message
news:e8k38f$mtt$[email protected]..
> Thank you. But still not completely understanding. I
have details. Thank
> you
> again for the help.
>
> This is the form tag:
>
> </form id="frm_delete" name="frm_delete"
method="POST"
> onSubmit="confirm_entry()"
action="<%=MM_editAction%>">
>
> This is the submit button:
> <input type="submit" name="Submit" value="Delete This
File!" />
>
> This is the JavaScript:
>
> <script language="JavaScript">
> <!--
> function confirm_entry()
> {
> input_box=confirm("Click OK or Cancel to Continue");
> if (input_box==true)
>
> {
> // Output when OK is clicked
> alert ("The File Will be deleted");
> }
>
> else
> {
> // Output when Cancel is clicked Option
>
> alert ("The File Has Not Been Deleted");
> }
>
> }
> -->
> </script>
> -
Hello,
I have a Model/Scene in PS/CS5 and I'm looking to batch multiple versions with a different texture map applied to each.
Here's the basic actions:
Open "Model" / Load texture "Name_01" from list / Rasterize / Export as PNG using texture file's naming convention, "Name_01" / Repeat...
This appears to be outside PS actions to accomplish.
Any thoughts or scripting gurus to recommend?
Thanks!xbytor2 wrote:
Can you record an action that does what you want for a particular model and texture?
Yes, but not entirely. I've got two hurdles...
1. I'm referencing a new texture file for each instance of my model and using that texture file's naming convention as the final exported PNG. I realize that I could do a batch rename after the fact, so this is not my main issue.
2. When doing this to a single file I can record an action for everything, but...
Since the batch of files I'm processing is referenced in the middle of my action (Load "Name_01" as a new texture for model), I don't see how to interpret it into a workable batched script.
This may require a combination of PS and Automator scripts, but that may be getting too heady for me alone.
Any help would be great!
Thanks -
Query on batch scripting - Archival
Hello,
I am totally new to batch script. Below is the requirement that needs to be developed using batch script. Please suggest on how to proceed and a good link to learn about batch scripting too.
Zip once in 2 weeks and deleted after a year.
Thanks and Regards,Hello,
You can use PowerShell to automate the job of Zip and delete them based on scheduled time lines. -
Hi
I have large database and i need to perform batch deleting without affecting the transaction log. So if I set the Recovery mode to Simple before deleting the transaction log will not grow ??
Thanks.Hi
I have large database and i need to perform batch deleting without affecting the transaction log. So if I set the Recovery mode to Simple before deleting the transaction log will not grow ??
Thanks.
You CANNOT delete records in sql server without getting information logged in transaction log. Please note every thing in SQL Server is logged and logging depends on recovery model used. When you use simple recovery logging will
almost be same as full just after checkpoint logs would be truncated and also when log file grows 70 % of its size. This can only not happen IF some ongoing transaction is not holding the VLF or requires the VLF(virtual
log file)
So you made good choice to delete in batches. Also have a look on Lock escalation
Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it
My Technet Wiki Article
MVP -
Deleting Records from Referential Tables
Hi,
Can anyone help me in deleting records from tables in a hierarcial manner. For e.g C refers B and B refers A. I need to delete data from all three tables related to a where clause in A.I tried using User_constraints and User_cons_columns views. But i am not able to find a hierarchial delete statement.
VenkateshDid you look into the option of specifying ON DELETE CASCADE for your foreign key constraints. That way, if you delete a
row from the master table Oracle will automatically go and delete the child rows. Take a look at the following script.
Here, when I delete a row from table A for NUM = 1 the child rows from table B (WHERE num = 1) are automatically deleted.
drop table b
drop table a
create table a (num number, name varchar2(40))
create table b (num number, name varchar2(40))
alter table a add constraint pk_a primary key(num)
alter table b add constraint fk_b_num foreign key (num) references a(num) on delete cascade
insert into a values (1, 'Test#1')
insert into a values (2, 'Test#2')
insert into b values (1, 'Referes#1')
insert into b values (2, 'Referes#2')
select * from a
select * from b
delete from a where num = 1
select * from a
select * from b
Sridhar,
Thanks a lot for your help.My exact need was to delete records in 50 tables starting with the key table for a specific condition in the key table.
Assume table A has 100 records,B 200 records,C 150 records,D 400 records, etc
When i want to delete some records in table A, i will not be able to do that as child records exists in table B and this structure will carry on till that last table in my application. How do i delete those specific records
Venkatesh -
Hi,
I am using Master Data Service for couple of months now. I can load, update, merge and soft delete data in MDS. Occasionally we even have to hard delete data from MDS. If we keep on soft deleting records in a MDS table eventually there will be huge number
of soft deleted records.
Is there an easy way to hard delete all the soft deleted records from all MDS tables in a specific Model.
Regards,
RehanWe did develop a Transact SQL procedure for this using the staging interface. It works and can be used freely :)
God Luck!
Jan Isacsson
USE [MDS]
GO
/****** Object: StoredProcedure [dbo].[AutoPurge] Script Date: 4/21/2015 10:39:21 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- To be used without warranty but it works even for collections
-- Jan Isacsson (www.independent.se) 2015-04-21
CREATE PROCEDURE [dbo].[AutoPurge]
@modelName nvarchar(200) = 'PDWmReferenceData',
@versionName nvarchar(200) = 'VERSION_1',
@entityName nvarchar(200) = NULL
AS
DECLARE @name nvarchar(200)
DECLARE @tableName nvarchar(200)
DECLARE @stagingName nvarchar(200)
DECLARE @collectionTable nvarchar(200)
DECLARE @collectionMemberTable nvarchar(200)
DECLARE @isFlat INT
DECLARE @sqlIsFlat NVARCHAR(512)
DECLARE @sqlGetEntityTable NVARCHAR(512)
DECLARE @sqlGetCollectionTable NVARCHAR(512)
DECLARE @sqlGetCollectionMemberTable NVARCHAR(512)
DECLARE @sqlGetStagingBaseTable NVARCHAR(512)
DECLARE @sqlLoadPurgeConsolidated NVARCHAR(512)
DECLARE @sqlLoadPurgeLeaf NVARCHAR(512)
DECLARE @sqlRinseStaging NVARCHAR(512)
DECLARE @sqlPurgeCollections NVARCHAR(512)
DECLARE @sqlCheckErrorStaging NVARCHAR(512)
DECLARE @batchTagName NVARCHAR(512)
DECLARE @executePurge NVARCHAR(512)
DECLARE @errorMsg NVARCHAR(512)
DECLARE @i INT
DECLARE @id INT
DECLARE leaf_entity_cursor CURSOR FOR
select e.ID, e.Name from
mdm.tblModel m,
mdm.tblEntity e
where
e.Model_ID = m.ID
and m.Name = @modelName
DECLARE noleaf_entity_cursor CURSOR FOR
select e.ID, e.Name from
mdm.tblModel m,
mdm.tblEntity e
where
e.Model_ID = m.ID
and m.Name = @modelName
and e.IsFlat = 0
-- Leaf purge
SET @batchTagName = '''AutoPurge'''
OPEN leaf_entity_cursor
FETCH NEXT FROM leaf_entity_cursor INTO @id, @name
WHILE @@FETCH_STATUS = 0
BEGIN TRY
if @name = @entityName or @entityName is null
BEGIN
SET @sqlGetEntityTable = N'select @tableName = EntityTable from mdm.tblEntity where ID = ' + CONVERT(nvarchar,@id)
EXEC sp_executesql
@query = @sqlGetEntityTable,
@params = N'@tableName NVARCHAR(100) OUTPUT',
@tableName = @tableName OUTPUT
SET @sqlGetStagingBaseTable = N'select @stagingName = StagingBase from mdm.tblEntity where ID = ' + CONVERT(nvarchar,@id)
EXEC sp_executesql
@query = @sqlGetStagingBaseTable,
@params = N'@stagingName NVARCHAR(100) OUTPUT',
@stagingName = @stagingName OUTPUT
SET @sqlRinseStaging = N'delete from stg.' + @stagingName + '_Leaf where BatchTag = ' + @batchTagName
EXEC sp_executesql @query = @sqlRinseStaging
SET @i = @@RowCount
SET @sqlLoadPurgeLeaf = N'insert into stg.' + @stagingName + '_Leaf (ImportType, ImportStatus_ID, BatchTag, Code) select 6, 0, ''AutoPurge'', Code from mdm.' + @tableName + ' where Status_ID = 2'
EXEC sp_executesql @query = @sqlLoadPurgeLeaf
SET @i = @@RowCount
if @i != 0
BEGIN
SET @executePurge = N'EXEC stg.udp_' + @stagingName + '_Leaf @VersionName = ''' + @versionName + ''', @LogFlag = 1, @BatchTag = ' + @batchTagName
EXEC sp_executesql @query = @executePurge
SET @i = @@RowCount
SET @sqlCheckErrorStaging = N'select ErrorCode from stg.' + @stagingName + '_Leaf where BatchTag = ' + @batchTagName + ' and ErrorCode != 0'
EXEC sp_executesql @query = @sqlCheckErrorStaging
SET @i = @@RowCount
if @i != 0
BEGIN
SET @errorMsg = 'Error in purging leaf entity: ' + CONVERT(nvarchar,@id)
RAISERROR (@errorMsg, 16, 1 )
END
END
END
FETCH NEXT FROM leaf_entity_cursor INTO @id, @name
END TRY
BEGIN CATCH
SET @errorMsg = ERROR_MESSAGE()
PRINT @errorMsg
BREAK
END CATCH
-- Consolidated purge
OPEN noleaf_entity_cursor
FETCH NEXT FROM noleaf_entity_cursor INTO @id, @name
WHILE @@FETCH_STATUS = 0
BEGIN TRY
if @name = @entityName or @entityName is null
BEGIN
SET @sqlGetEntityTable = N'select @tableName = HierarchyParentTable from mdm.tblEntity where ID = ' + CONVERT(nvarchar,@id)
EXEC sp_executesql
@query = @sqlGetEntityTable,
@params = N'@tableName NVARCHAR(100) OUTPUT',
@tableName = @tableName OUTPUT
SET @sqlGetStagingBaseTable = N'select @stagingName = StagingBase from mdm.tblEntity where ID = ' + CONVERT(nvarchar,@id)
EXEC sp_executesql
@query = @sqlGetStagingBaseTable,
@params = N'@stagingName NVARCHAR(100) OUTPUT',
@stagingName = @stagingName OUTPUT
SET @sqlRinseStaging = N'delete from stg.' + @stagingName + '_Consolidated where BatchTag = ' + @batchTagName
EXEC sp_executesql @query = @sqlRinseStaging
SET @i = @@RowCount
SET @sqlLoadPurgeLeaf = N'insert into stg.' + @stagingName + '_Consolidated (ImportType, ImportStatus_ID, BatchTag, HierarchyName, Code) select 4, 0, ''AutoPurge'', ''' +@entityName + ''', Code from mdm.' + @tableName + ' where Status_ID = 2'
EXEC sp_executesql @query = @sqlLoadPurgeLeaf
SET @i = @@RowCount
if @i != 0
BEGIN
SET @executePurge = N'EXEC stg.udp_' + @stagingName + '_Consolidated @VersionName = ''' + @versionName + ''', @LogFlag = 1, @BatchTag = ' + @batchTagName
EXEC sp_executesql @query = @executePurge
SET @i = @@RowCount
SET @sqlCheckErrorStaging = N'select ErrorCode from stg.' + @stagingName + '_Consolidated where BatchTag = ' + @batchTagName + ' and ErrorCode != 0'
EXEC sp_executesql @query = @sqlCheckErrorStaging
SET @i = @@RowCount
if @i != 0
BEGIN
SET @errorMsg = 'Error in purging consolidated entity: ' + CONVERT(nvarchar,@id)
RAISERROR (@errorMsg, 16, 1 )
END
END
SET @sqlGetCollectionTable = N'select @collectionTable = CollectionTable from mdm.tblEntity where ID = ' + CONVERT(nvarchar,@id)
EXEC sp_executesql
@query = @sqlGetCollectionTable,
@params = N'@collectionTable NVARCHAR(100) OUTPUT',
@collectionTable = @collectionTable OUTPUT
SET @sqlGetCollectionMemberTable = N'select @collectionMemberTable = CollectionMemberTable from mdm.tblEntity where ID = ' + CONVERT(nvarchar,@id)
EXEC sp_executesql
@query = @sqlGetCollectionMemberTable,
@params = N'@collectionMemberTable NVARCHAR(100) OUTPUT',
@collectionMemberTable = @collectionMemberTable OUTPUT
SET @sqlPurgeCollections = N'delete mdm.' + @collectionMemberTable + ' from mdm.' + @collectionTable + ' cn inner join mdm.' + @collectionMemberTable +
' cm on cm.Parent_CN_ID = cn.ID where cn.Status_ID = 2'
EXEC sp_executesql @query = @sqlPurgeCollections
SET @i = @@RowCount
if @i != 0
BEGIN
SET @sqlPurgeCollections = N'delete from mdm.' + @collectionTable + ' where Status_ID = 2'
EXEC sp_executesql @query = @sqlPurgeCollections
SET @i = @@RowCount
END
END
FETCH NEXT FROM noleaf_entity_cursor INTO @id, @name
END TRY
BEGIN CATCH
SET @errorMsg = ERROR_MESSAGE()
PRINT @errorMsg
BREAK
END CATCH
CLOSE noleaf_entity_cursor
DEALLOCATE noleaf_entity_cursor
GO
JAIS
Maybe you are looking for
-
HT1212 i have forgotten my passcode and i have tried the restore option but it just wont work
I tried restoring it but it wont work it just keeps coming up with the sign saying "you cant use itunes with this device until you put in passcode". And its getting really fustrating please help
-
Can't create new BeehiveOnline Workspace "You do not have the required..."
I'm trying to create a new BeehiveOnline Workspace. I follow the instructions from the FAQ, but as soon as I click on the "New/Workspace" option, I receive this error "You do not have the required privileges to create a workspace in this Location" Th
-
Finder has colors all messed up.
My problem is that when I log into the administrator account on my Aluminum iMac, all of the colors are messed up, and the screens looks like it was drawn from a comic book. This only affects the administrator account, when I log into the other accou
-
Flash CS6 Crashes every time I create or open a project. How to fix?
I have updated flash, windows and java, have re-installed flash CS6, restarted my computer and reset my preferences but still flash crashes. This is what it looks like: As soon as I click anywhere in the program it changes to the not responding scree
-
Where can i find the 'notes' icon on my iMac?
Bought an iMac a couple of years ago and only just realised the 'Notes' icon is not in the Applications so I can't sync notes with m iPhone or iPad. Can anyone help with this?