Results 1 to 14 of 14
  1. #1
    Join Date
    Sep 2003
    Posts
    17

    Question Unanswered: how to copy a table(include the data in table)?

    I just want to change a name.
    thanks in advance.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    select * into newtable from oldtable


    rudy
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Sep 2003
    Posts
    17
    But I also want copy the PK,restriced condition...etc.

    "Select into..."just copy the data in table,and it requires a created table,
    I need a more simple and powerful solution.

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    not, it does not require a created table, it creates the new table "on the fly"

    but you're right, it doesn't copy that other stuff

    i'm not sure there is a simpler solution
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1

    Wink

    Hello there,
    why don't try
    DoCmd.CopyObject , "newTableName", acTable, "oldTableName"


    Good luck

  6. #6
    Join Date
    Sep 2003
    Posts
    17
    hammbakka:
    Thanks for your help.but your method could not copy the foreign key of the table.I need a table the same as former except the name.

  7. #7
    Join Date
    Jul 2003
    Location
    Amsterdam, Nederland
    Posts
    450

    Lightbulb 2 simple

    Right click on the table
    choose copy
    then click on nothing(white tablet) right click again paste
    Give a name and choose structure and data


    finnito

  8. #8
    Join Date
    Sep 2003
    Posts
    17

    Re: 2 simple

    Originally posted by Marvels
    Right click on the table
    choose copy
    then click on nothing(white tablet) right click again paste
    Give a name and choose structure and data


    finnito
    Oh,Both sql and ado are available,But mouse not.

    I think you are joking^_^

  9. #9
    Join Date
    Oct 2003
    Location
    Roanoke, Va
    Posts
    445

    Question

    Originally posted by luohualiushui
    hammbakka:
    Thanks for your help.but your method could not copy the foreign key of the table.I need a table the same as former except the name.
    I'm confused here. I just tried the CopyObject method and it copied the table exactly including indexes. I must be missing something.

    Gregg

  10. #10
    Join Date
    Sep 2003
    Posts
    17
    Originally posted by basicmek
    I'm confused here. I just tried the CopyObject method and it copied the table exactly including indexes. I must be missing something.

    Gregg
    CopyObject can not maintain the relation to the other table,I main the reference.

  11. #11
    Join Date
    Oct 2003
    Location
    Roanoke, Va
    Posts
    445

    Question

    Originally posted by luohualiushui
    CopyObject can not maintain the relation to the other table,I main the reference.
    Do you mean the relationship?

    This can be built in code if this is what you want to do.

    Gregg

  12. #12
    Join Date
    Sep 2003
    Posts
    17
    yes,can you give me a sample?
    thanks very much!

  13. #13
    Join Date
    Oct 2003
    Location
    Roanoke, Va
    Posts
    445

    Smile

    Originally posted by luohualiushui
    yes,can you give me a sample?
    thanks very much!
    Dim db as Database, rel as Relation

    Set db = CurrentDb
    Set rel = db.CreateRelation("NewRelationName", "TableName", "ForeignTableName")

    With rel
    .Fields.Append rel.CreateField("FieldName")
    .Field!FieldName.ForeignName = "ForeignKeyFieldName"
    End With

    db.Relations.Append Rel1

    Check out the CreateRelation Method in the Visual Basic reference that ships with Access. That's pretty much the code they used. I tested it to make sure it works. Double check for typing errors since I typed and did not copy and paste.

    Hope it works.

    Gregg

  14. #14
    Join Date
    Sep 2003
    Posts
    17
    This is just what i need.
    Thank basicmek very much.
    thanks everyone give me advice too.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •