Results 1 to 13 of 13
  1. #1
    Join Date
    Dec 2003
    Posts
    28

    Unanswered: set a table to be emty?

    Hello!

    In my GUI for Mysql there is a command "emty" that delete all the rows in current table.

    How do I express that in normal syntax?

    I dont want to drop the table just delete all the rows.

    Regards// D_S

  2. #2
    Join Date
    Jan 2004
    Location
    Singapore
    Posts
    89

    Re: set a table to be emty?

    Originally posted by digital_storm
    Hello!

    In my GUI for Mysql there is a command "emty" that delete all the rows in current table.

    How do I express that in normal syntax?

    I dont want to drop the table just delete all the rows.

    Regards// D_S
    TRUNCATE TABLE TableName
    Thanks and Regards,

    Praveen Pulikunnu

  3. #3
    Join Date
    Jul 2003
    Posts
    8

    Re: set a table to be emty?

    You may also simply do the following:

    DELETE FROM [tablename];

  4. #4
    Join Date
    Dec 2003
    Posts
    28
    Hello,

    If I do "DELETE" I will also delete the preferences of that table or?

    Regards // D_S

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    praveenpr, in mysql truncate actually drops and recreates the table

    this is very fast but there is a drop involved, which d_s didn't want, for reasons which are not yet clear

    d_s, what do you mean by "preferences"?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  6. #6
    Join Date
    Dec 2003
    Posts
    28
    Hello,

    For example "Alter Table"

  7. #7
    Join Date
    Mar 2004
    Posts
    480
    DS, you still aren't clear. Do you mean you have used Alter Table on this particular table and are worried you will lose any changes you have made? Or do you mean if you run the delete you won't be able to use Alter table in the future?

    If you use

    DELETE from tablename;

    you will delete all the table data, but the schema will still be there for the table itself. You won't change the table in any way other than dropping what is contained in it. You will still be able to alter the table in the future to add new columns etc.

  8. #8
    Join Date
    Dec 2003
    Posts
    28
    Hello,

    You have to excuse me.... I will explain.
    I have a table called TEMP which I store temporary data, this table is "ALTERED BY" "playnr".

    When I have used my temporary data I want to delete all data in my table "TEMP" but next time data is stored it will be altered by "playnr" again


    Regards// D_S

  9. #9
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    your last description is very confusing

    first of all, if the table hangs around, it isn't really temporary, is it

    second, what does altered by "playnr" again mean?

    what exactly is being altered? are you adding a "playnr" column that wasn't there before?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  10. #10
    Join Date
    Dec 2003
    Posts
    28
    Hello,

    1) The table is static...the information in that table are used once and then I want to set my table as empty.
    2) I have predefined colums and...
    3) I have a column called "playnr" in my table TEMP (its my "primary key")

    I hope this helps..

    Thanks again! // D_S

  11. #11
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    aha, the primary key

    no, you'll be fine

    TRUNCATE resets auto_increments, but leaves constraints on the table
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  12. #12
    Join Date
    Dec 2003
    Posts
    28
    Hello,

    Ok....

    Thank you for your help!

    Regards // D_S

  13. #13
    Join Date
    Oct 2003
    Location
    Buenos Aires, Argentina
    Posts
    20
    Yes..
    you must use the "TRUNCATE TableName" query.
    I'll delete all the data, reset the autoincrements but the structure will be the same.

    ------------------------------------
    Thanx
    ------------------------------------
    http://www.iespana.es/greatavatar/FIRMA/firma.jpg

Posting Permissions

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