MySQL Delete all rows from table and reset ID to zero

SET FOREIGN_KEY_CHECKS = 0; — disable a foreign keys check
SET AUTOCOMMIT = 0; — disable autocommit
START TRANSACTION; — begin transaction

DELETE FROM table_name;
ALTER TABLE table_name AUTO_INCREMENT = 1;
— or
TRUNCATE table_name;
— or
DROP TABLE table_name;
CREATE TABLE table_name ( … );

SET FOREIGN_KEY_CHECKS = 1; — enable a foreign keys check
COMMIT; — make a commit
SET AUTOCOMMIT = 1 ;

댓글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

%d 블로거가 이것을 좋아합니다: