×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

COPY INDEXES
4

COPY INDEXES

COPY INDEXES

(OP)
Hi all
how can i copy the INDEXES from table to another table

RE: COPY INDEXES

Assuming that you have a compound index (CDX file), you could do something like this:

CODE -->

SELECT SourceTable
lnCount = ATAGINFO(laTags)
SELECT TargetTable
FOR lnI = 1 TO lnCount
  lcExpr = laTags(lnI, 3)
  lcName = laTags(lnI, 1)
  INDEX ON &lcExpr TAG &lcName
ENDFOR 

I haven't tested this, but I think it should mor-or-less work. You will need to adjust it if you also want to specify a collating sequence and an index order (ascending vs descending).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: COPY INDEXES

By the way, Ahmed, could you please edit your post so as to get rid of all the blank space below your question. Thanks.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: COPY INDEXES

(OP)
can i do this through the COPY INDEXES command
I think it would be easier but I do not know how to write this command

RE: COPY INDEXES

You can copy index with table when you USE someold.dbf and COPY TO somenew.DBF WITH CDX

That's all to it, all tags are copied, too.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: COPY INDEXES

COPY INDEXES is a command to integrate IDX indexes into a CDX file. COPY INDEXES doesn't exist to copy an index from one to another table. Just read the help.

COPY TO WITH CDX also works with a FOR clause not copying all data, the index tags then also are just built for the copied data. Copying indexes separately after you already copied data or did SQL-Select INTO TABLE is not working that easy, you will need to know the index expression and recreate the index by it, and that does not work for all index types, PRIMARY indexes cannot be created by INDEX ON, for example.

So the best way to have a table with same indexes as another is via COPY TO.

You could also go the much more general route of recreating tables with the help of the code GENDBC creates from a DBC (also available as GENDBCX in some VFPX github), which means all the CREATE TABLE, INDEX ON and other commands necessary to create some DBC, with its DBFs CDXes. And then pull out whatever partial things you need.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: COPY INDEXES

Quote:

can i do this through the COPY INDEXES command

No. If you read the Help for COPY INDEXES, you will see that it is used to create a compound index file (a CDX file) from individual IDX files, which is not what you want.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: COPY INDEXES

(OP)
Mike :i want that but i need one example because help not include example for that .

RE: COPY INDEXES

Use yourtable
Copy to yourcopy with cdx 

RE: COPY INDEXES

Quote (amedoo3000)

Mike :i want that

No, you don't. You asked:

Quote (amedoo3000)

how can i copy the INDEXES from table to another table
And this is not what COPY INDEXES offers, it turns IDX into CDX for the same table.

Notice copying an index including its data can only work out and result in an index pointing a seek inside this index to the correct records, if not only the index but also the data matches. For the fourth or fifth time from three persons, I point out the command you could use while you create the table data copy, too, is SELECT source and then COPY TO target.DBF WITH CDX.

It's clear that your situation is having two tables. You can't copy over the index from one to another table, it's not sufficient that the structure is the same.

What you can do when you have other data, just partial data or even an empty second DBF is what Mike showed you in his first answer, you can copy over the index expressions and recreate the same index tag names with the same expression to let the same SEEK/INDEXSEEK or rushmore optimizations work with the second table, too.

There is neither a source nor a target alias as option of the COPY INDEXES command. You miss to understand the syntax description. You specify tag names associated with IDX file names and a CDX file name as target. The best you could do is copy from table1tag1.idx, table1tag2.idx to table2.cdx, but the CDX you create that way won't work! It's not designed for table2, even if table2 is a structural copy. The index data points to records in table1.dbf and all the record numbers would be wrong for table2, SEEKing in that cdx would guide you to totally wrong records.

Again, in your situation you have a simpler solution if you go back to the step of creating the second table with data AND cdx at the same time with COPY TO WITH CDX or you have to iterate all indexes of the first table and recreate them with INDEX ON, as far as that's possible (not with primary indexes). You better change the code creating the second table to do that with COPY TO WITH CDX as that's the step where you can copy the indexes, all of them, even primary.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: COPY INDEXES

I wish people wrote more in depth about what they really want, and that's for several reasons. One is so that we don' misunderstand the question. Another is that we may have a better solution to what the OP actually want to accomplish.

RE: COPY INDEXES

(OP)
Well all of the above is good and excellent but what if I wanted to move information from table A to table B with the same index of table A by simple steps
I was thinking of copying Table A to Table B and then clearing all the data of Table B ..... Now how can I transfer all the data of Table A to Table B in this case?

RE: COPY INDEXES

And to get an empty tableB with indexes:

CODE

Use tableA
Copy To tableB with CDX FOR .F. 
This just uses very basic knowledge about how FOR clauses work.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: COPY INDEXES

Quote:

I wanted to move information from table A to table B with the same index of table A by simple steps

Well, if you had asked for that in the first place, that is what you would have got.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: COPY INDEXES

I already answered that question. Do you read the answers at all, before you ask?

RE: COPY INDEXES

(OP)
thank for all
now every thing is Ok

Greetings

Ahmed

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close