LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-11-2011, 12:01 AM   #1
swapna sree
LQ Newbie
 
Registered: Jul 2011
Location: Hyderabad
Posts: 20

Rep: Reputation: 0
how to drop a table using shell script


Hi team,

Am inserting the data into a new table ,the data is coming from Select statement.
like

select col1,col2,col3
into tempdb..tableNew
from tempdb..tableSource
where col1 = 2

so before inserting into tableNew,it should drop the table if exists in tempdb

am using drop table tempdb..tableNew but its of no use in shell script but if i run the same in Database its droping the table

Can anyone help me on this.

Regards
Swapna
 
Old 08-11-2011, 05:31 AM   #2
sieira
Member
 
Registered: Dec 2007
Location: Alcalá de Henares (Madrid)
Distribution: Debian
Posts: 40

Rep: Reputation: 16
I don't understand what you mean, I wonder if you're trying something like this:

Code:
#!/bin/bash
mysql -e select col1,col2,col3 
into tempdb..tableNew
from tempdb..tableSource
where col1 = 2
Could you be more specific, please?
  1. What database engine are you using
  2. How are you building you script
  3. How do you run your drop table statement, both whan you do it from the engine, and from the script
 
Old 08-12-2011, 05:54 AM   #3
swapna sree
LQ Newbie
 
Registered: Jul 2011
Location: Hyderabad
Posts: 20

Original Poster
Rep: Reputation: 0
hey i got it..


if exists (select * from sysobjects where type='U' and name=' tableNew')
drop table tableNew
go

select col1,col2,col3
into tempdb..tableNew
from tempdb..tableSource
where col1 = 2
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Shell script to table RAW device values kayasaman Programming 8 04-04-2011 01:34 AM
[SOLVED] shell script to get count of records in a mysql table Quakeboy02 Programming 3 10-24-2010 10:21 AM
iptables: use of DROP in nat table Robert S Linux - Security 2 04-24-2009 12:07 PM
shell script/command for converting columns/table onto a single line skuz_ball Programming 9 11-30-2007 03:02 AM
update oracle table using shell script ann124 Programming 1 12-06-2004 02:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration