English 中文(简体)
加入汽车加油场
原标题:Insert into an auto increment field
  • 时间:2011-05-10 16:32:52
  •  标签:
  • mysql

i have a table in which i have started the auto increment id at 10000 so that i have 10000 values reserved for manual insertion of values from admins. However when doing an insert into MyTable(ID,Name,Value) VALUES(500,"Test","Test") i do a select and it ignored my ID i gave it and pushes in into the next 10,000 range. Any suggestions on fixing this or what may be wrong? The code above is of course pseudo but i can give a real code example if it doesnt make sense.

问题回答

在你回答你的问题之前,我必须警告你:extremely你试图这样做的坏做法。 不要让我错了,许多人试图做你重新做的事情,这根本不是应该做的事情。

页: 1 国际发展法是主要的关键。 主要的钥匙用于在表格中独一无二地确定一行。 这就是说。 除此以外,它没有任何其他特别意义。

So what does that mean for you? It means that your idea that you will "reserve" 1 - 10k for admins is bad. Why is it bad? Because you re tampering with the primary key. You should never decide what the value of primary key should be, that s databases job for many reasons (consistency for example). The other thing why it s bad is that you have limited someone to only 10k possible entries. On the other hand, how will you calculate what the next entry for admins is? What if you have entered 1, 2, 3, 4 and then you delete entry with ID = 3? What happens then? What s your next in sequence value? 3 or 5?

尽管如此,你或许应当重新考虑你们的战略。 为什么不增加一个“isAdmin”领域,告诉你一个行政机构是否张贴了东西?





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签