Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert new row with id 1

Tags:

sql

mysql

Is there any possibility to delete the entire Data in table and insert new rows with id starts from 1

Delete Command helps to remove the data from table when we trying to insert new row that id will be Last inserted row id+1(if last inserted id is 5 then new id should be 6) but i want to store that id as 1

any suggestions other than truncate command, Thanks in advance

like image 922
Satish Avatar asked Jul 11 '13 05:07

Satish


People also ask

How do you add to a specific row?

To insert a row into a table, you need to specify three things: First, the table, which you want to insert a new row, in the INSERT INTO clause. Second, a comma-separated list of columns in the table surrounded by parentheses. Third, a comma-separated list of values surrounded by parentheses in the VALUES clause.

How do I add a new row in SQL query?

Here is the basic syntax for adding rows to a table in SQL: INSERT INTO table_name (column1, column2, column3,etc) VALUES (value1, value2, value3, etc); The first line of code uses the INSERT statement followed by the name of the table you want to add the data to.

How do I get the unique ID for the last inserted row?

If you insert a record into a table that contains an AUTO_INCREMENT column, you can obtain the value stored into that column by calling the mysql_insert_id() function.

How do I insert one row in a table?

Place your cursor in the table where you want to insert the row or column. Right-click, then select one of the following: Table > Insert Row Above.


1 Answers

After deleteing all records do

ALTER TABLE tablename AUTO_INCREMENT = 1

Note

From MySQL Docs : Link

You cannot reset the counter to a value less than or equal to any that have already been used. For MyISAM, if the value is less than or equal to the maximum value currently in the AUTO_INCREMENT column, the value is reset to the current maximum plus one. For InnoDB, if the value is less than the current maximum value in the column, no error occurs and the current sequence value is not changed.

like image 106
Mudassir Hasan Avatar answered Oct 01 '22 00:10

Mudassir Hasan