auto-increment

How to add auto increment id according to a group in mysql

青春壹個敷衍的年華 提交于 2019-11-29 04:35:24
Here is the format of the table: indexer group name id 1 abc a 2 abc b 3 xyz c 4 abc e 5 xyz d Now i want it to be like, indexer group name id 1 abc a 1 2 abc b 2 3 xyz c 1 4 abc e 3 5 xyz d 2 "id" should auto increment according to "group" Try this: update yourtable t1 join ( select tt.indexer, @rowno := if(@grp = `group`, @rowno + 1, 1) as id, @grp := `group` from (select * from yourtable order by `group`, indexer) tt cross join (select @rowno := 0, @grp := null) t ) t2 on t1.indexer = t2.indexer set t1.id = t2.id Demo Here Edited: If you want to insert a new row, you have to do it like this

void * arithmetic

坚强是说给别人听的谎言 提交于 2019-11-29 03:01:21
#include<stdio.h> int main(int argc,char *argv[]) { int i=10; void *k; k=&i; k++; printf("%p\n%p\n",&i,k); return 0; } Is ++ a legal operation on void* ? Some books say that it's not but K & R doesn't say anything regarding void * arithmetic ( pg. 93,103,120,199 of K &R 2/e) Please clarify. PS : GCC doesn't complain at least in k++. It is a GCC extension . In GNU C, addition and subtraction operations are supported on pointers to void and on pointers to functions. This is done by treating the size of a void or of a function as 1. If you add the -pedantic flag it will produce the warning:

void * arithmetic

你说的曾经没有我的故事 提交于 2019-11-29 02:59:28
#include<stdio.h> int main(int argc,char *argv[]) { int i=10; void *k; k=&i; k++; printf("%p\n%p\n",&i,k); return 0; } Is ++ a legal operation on void* ? Some books say that it's not but K & R doesn't say anything regarding void * arithmetic ( pg. 93,103,120,199 of K &R 2/e) Please clarify. PS : GCC doesn't complain at least in k++. It is a GCC extension . In GNU C, addition and subtraction operations are supported on pointers to void and on pointers to functions. This is done by treating the size of a void or of a function as 1. If you add the -pedantic flag it will produce the warning:

How to import text file to table with primary key as auto-increment

大城市里の小女人 提交于 2019-11-29 01:34:21
I have some bulk data in a text file that I need to import into a MySQL table. The table consists of two fields .. ID (integer with auto-increment) Name (varchar) The text file is a large collection of names with one name per line ... (example) John Doe Alex Smith Bob Denver I know how to import a text file via phpMyAdmin however, as far as I understand, I need to import data that has the same number of fields as the target table. Is there a way to import the data from my text file into one field and have the ID field auto-increment automatically? Thank you in advance for any help. Not correct

I need to auto_increment a field in MySQL that is not primary key

岁酱吖の 提交于 2019-11-29 01:04:51
Right now, I have a table whose primary key is an auto_increment field. However, I need to set the primary key as username , date (to ensure that there cannot be a duplicate username with a date). I need the auto_increment field, however, in order to make changes to row information (adding and deleting). What is normally done with this situation? Thanks! Just set a unique index on composite of (username, date). ALTER TABLE `table` ADD UNIQUE INDEX `name` (`username`, `date`); Alternatively, you can try to ALTER TABLE `table` DROP PRIMARY KEY, ADD PRIMARY KEY(`username`,`date`); and I think in

MSSQL Select statement with incremental integer column… not from a table

独自空忆成欢 提交于 2019-11-29 00:59:06
I need, if possible, a t-sql query that, returning the values from an arbitrary table, also returns a incremental integer column with value = 1 for the first row, 2 for the second, and so on. This column does not actually resides in any table, and must be strictly incremental, because the ORDER BY clause could sort the rows of the table and I want the incremental row in perfect shape always... Thanks in advance. --EDIT Sorry, forgot to mention, must run on SQL Server 2000 For SQL 2005 and up SELECT ROW_NUMBER() OVER( ORDER BY SomeColumn ) AS 'rownumber',* FROM YourTable for 2000 you need to do

Will MySQL reuse deleted ID's when Auto Increment is applied

你离开我真会死。 提交于 2019-11-28 23:09:25
http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html That document I'm reading seems to say something like: "In this case (when the AUTO_INCREMENT column is part of a multiple-column index), AUTO_INCREMENT values are reused if you delete the row with the biggest AUTO_INCREMENT value in any group." I don't really understand what's being said there. Aren't the values supposed to be reused automatically? Thanks in advance... InnoDB resets the auto_increment field when you restart the database. When InnoDB restarts, it finds the highest value in the column and then starts from there.

MySQL: bigint Vs int

穿精又带淫゛_ 提交于 2019-11-28 21:03:12
I have been using int(10) and just noticed that Wordpress uses bigint(20) - What is different to use bigint(20) and int(10) for id auto increment? Which one should I use for id column? `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, Vs `id` int(10) unsigned NOT NULL AUTO_INCREMENT, Thanks. The difference is purely in the maximum value which can be stored (18,446,744,073,709,551,615 for the bigint(20) and 4,294,967,295 for the int(10), I believe), as per the details on the MySQL Numeric Types manual page. Incidentally, the use of (20) and (10) is largely irrelevant unless you're using

SQL-How to Insert Row Without Auto incrementing a ID Column?

谁说胖子不能爱 提交于 2019-11-28 21:02:05
问题 I have a table that has a forced auto increment column and this column is a very valuable ID that is retained through out the entire app. Sorry to say it was poor development on my part to have this be the auto incrementing column. So, here is the problem. I have to insert into this table an ID for the column that has already been created and removed from the table. Kind of like resurrecting this ID and putting it back into the table. So how can I do this programatically do this without

auto increment ID in H2 database

瘦欲@ 提交于 2019-11-28 19:30:54
问题 Is there a way to have an auto_incrementing BIGINT ID for a table. It can be defined like so id bigint auto_increment but that has no effect (it does not increment automatically). I would like to insert all fields but the ID field - the ID field should be provided by the DBMS. Or do I need to call something to increment the ID counter? 回答1: It works for me. JDBC URL: jdbc:h2:~/temp/test2 drop table test; create table test(id bigint auto_increment, name varchar(255)); insert into test(name)