Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Re Sorting Tables
Message
From
02/05/2002 10:29:09
 
 
To
30/04/2002 17:52:51
Ian Matthews
Up & Running Technologies Inc
Chestermere, Alberta, Canada
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00651133
Message ID:
00651853
Views:
25
Here is a routine which will reorg all tables in the DBC. It has an added benefit in packing the table / Memos.
local lerror, laFiles(1), lcPkey, i, lcError 
close all
close databases all
open database Yourdatabase
lcError = on('error')
on error lerror = .t.
for i = 1 to adbobjects(laFiles,"TABLE")
	use (laFiles(i)) exclusive alias lfile
	if not lerror and isexclusive('lFile')
		lcPkey = dbgetprop(laFiles(i),"TABLE","PRIMARYKEY")
		if not empty(lcPkey)
			set order to (lcPkey)
			copy to reorgwork
			zap
			append from work
		endif
		use
	else
		lerror = .f.
	endif
endfor

erase 'reorgwork.dbf'
erase 'reorgwork.fpt'
erase 'reorgwork.cdx'
close all
if not empty( lcError )
    on error &lcError
else
    on error
endif
Test this code first ( I just wrote it )

Glenn

>How can I easily sort a table based on the primary key?
>
>I wrote some FoxPro 6 code a few years ago (now with SP5) and now the client has a fair amount of data in the DB. I would like to resort most (or all) of the tables in that DB based on the primary key of each table.
>
>I have spent the last 2.5 hours goofing with SORT, COPY STRUCTURE, APPEND FROM... and combinations there of. In the end all I ended up with was frustration. I am certain that I ran a couple of simple commands when I imported their old data into the 'new' database a few years ago but I just can not seem to figure out the process. Surely, there is an easy way to do this.
>
>Any suggestions would be appreciated.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform