Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 28th, 2005, 02:20 AM
Authorized User
 
Join Date: Nov 2005
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default How can I write query for override a table??

Hello All,

  As u know, If we use INTO clause using SELECT then, we can create new table.. But what if everytime, I want to selecet particular records and want to store in same table, then I must override tha table everytime, Does anyone know, how can we write query with SELECT clause that, everytime It should create same table name and also it should override with same or different data..

  Thanks..


~~Dev~~
__________________
~ ~ ~ There is no Right, There is no Wrong, KNOWLEDGE is Only the POWER ~ ~ ~
 
Old November 28th, 2005, 02:23 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

You would have to check if the table exists first, if it does, drop it, then execute your new select into statement.
 
Old November 29th, 2005, 03:00 AM
Authorized User
 
Join Date: Nov 2005
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hello jbenson001

  First of all, thanks for the idea, but Sir, could u tell me the query, i am sure that everytime table will be exists.. so how can we write such a single query, which can not only check but also it table exits, drop it and override it..

   Waiting for the reply..


~~Dev~~
 
Old November 29th, 2005, 11:25 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

   What do you mean "override"? Do you want to simply just continue to Insert Rows to the table if it already exists? If that is the case, if the table already exists, you CANNOT use Select Into. You will need to use an Insert Into.

Jim

 
Old November 30th, 2005, 03:14 AM
Authorized User
 
Join Date: Nov 2005
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hye J.Benson,

   First of all, let me tell u Sir, that, I don't want to continuing INSERTing records in table if it is exist..

   Let me clear this time, In my VB application, everytime when it will run, from my table (say it has 10 records), it is going to display on first maximum 5 records.. got it? So,what's happening that table is updating constantly, so, what i want to do is, everytime when i run my VB application, it should display only first 5 maximum records, whether table has only 5 records or 50 records..

  I have just used following query, right now, which can create table one time, but not for everytime.. got it? SO, please suggest me some query, which can override that same table eveytime when i run my VB applilcation..

==============================================
  SELECT TOP 5 buyers INTO top_buy FROM trade ORDER BY buyers DESC
==============================================

  Here, I am displaying top 5 buyers from table called "trade" and everytime, when I could run my VB application the overriding table could be "top_buy"..

  Hope, I have cleared the picture now..



~~Dev~~
 
Old November 30th, 2005, 11:04 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

I would create a stored procedure. From there you can use the if...exits command to check if the table exists:

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[top_buy]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[top_buy]
GO

--Then do your insert here ...


 
Old December 1st, 2005, 12:41 AM
Authorized User
 
Join Date: Nov 2005
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks J.Benson..

   Its working, keep in touch..




                                            ~~Dev~~
 
Old December 1st, 2005, 01:15 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Glad it is working :)

Jim






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use VBA to Read/Write a Access Query Gino Liu Access VBA 2 January 7th, 2012 04:03 AM
Converting blank spaces to write a table name. SKE Classic ASP Databases 3 April 12th, 2005 01:32 PM
VB6 with Excel write using SQL query tmiller1 Excel VBA 3 March 9th, 2005 01:26 AM
plsssssssssssss help to write sql query sush_blr Beginning VB 6 4 February 1st, 2005 02:15 AM
ASP Table write out aware Classic ASP Basics 2 September 18th, 2003 02:03 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.