auto-increment

MySQL Auto Increment?

跟風遠走 提交于 2019-12-11 11:21:12
问题 I have 2 different MySQL servers. One is 5.6.12 the other 5.5.25a. In the 5.5 version server I can do this: ALTER TABLE AUTO_INCREMENT = 100; ALTER TABLE AUTO_INCREMENT = 50; The 5.6 version only allows me to change the auto_increment to a higher value than auto_increment is in that moment. Of course I'm not trying to change the value to a lower value than the record that has the maximum value. Both MySQL servers are InnoDB I need to use that commen in the newest version Any clue? 回答1: This

Using variable in setting mysql INNODB AUTO_INCREMENT table value

浪尽此生 提交于 2019-12-11 10:06:51
问题 I try to (re)set the auto_increment value to the value of a variable, but it fails: CREATE TABLE test_table ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=1; SET @tmpvar = 12345; ALTER TABLE test_table AUTO_INCREMENT=@tmpvar; The last command fails with: ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@tmpvar' at line 1 Is it not

MySQL - Auto_increment by 10

五迷三道 提交于 2019-12-11 06:57:20
问题 How do I set the auto_increment column in such a way that it increments by 10 for each record insert. For eg: Instead of the default auto_increment by 1, insert into temptable (name) values('abc'),('def'); select * from temptable; id|name 1|abc 2|def auto_increment by 10, id|name 10|abc 20|def 回答1: You would have to change the auto_increment_increment setting, however this would apply to all tables at once. I don't think there is a per-table increment setting. This is usually not really a

Reset auto increment

纵然是瞬间 提交于 2019-12-11 06:49:43
问题 My question starts here: How to setup auto increment for Service-Based Database So if I have to go this way to reset auto increment after deleting a table row: http://befused.com/mysql/reset-auto-increment first time I have deal with T-SQL extension and SQL generally. What is wrong here, not sure if I got it right: CREATE TABLE [dbo].[Tab1] ( [Id] INT IDENTITY (1, 1) NOT NULL, [Phrase] TEXT NOT NULL, PRIMARY KEY CLUSTERED ([Id] ASC) ); SELECT MAX( Id ) FROM [Tab1] ; ALTER TABLE Tab1 AUTO

Auto increment considering Tenant id

偶尔善良 提交于 2019-12-11 06:45:25
问题 I'm using SQL Server and need to keep an accounting number with reference to the tenant id. I cannot use the auto increment id because it is sequentially increments and has gaps in the client applications. I couldn't use computed columns as aggregate functions like Max is not allowed What would be the best approach for this? 回答1: You also can process when insert data, For example: insert into table1(ID,TenantId,PaymentId) select 6,2,isnull(max(PaymentId)+1,1) from table1 where TenantId=2

How auto-increment within a subset of the table MYSQL

淺唱寂寞╮ 提交于 2019-12-11 06:18:14
问题 To illustrate my problem I will use the analogy of authors and books. I have 2 tables "author" and "books". Authors are unique and books are tied to a specific authors using a foreign key constraint. I was wondering if it was possible to have a column called "booknum" in the "books" table that auto-increment within the subset of a single author. So if the table has 100 rows and im inserting the 4th book of an author it puts a 4 into the "booknum" column. For example if the books table had 6

Auto Increment not working in android SQLite Database

送分小仙女□ 提交于 2019-12-11 05:38:35
问题 I've got a running database but the primary key won't auto increment. Does anyone know what the problem could be? The code is as following // Database name and Version private static final String DATABASE_NAME = "kmky_database.db"; private static final int DATABASE_VERSION = 1; // Database Table private static final String TABLE_NAME = "logs"; private static final String COLUMN_ID = "_id"; private static final String COLUMN_PHONENUMBER = "phonenumber"; private static final String COLUMN_TYPE

insert with unnest function - skips a number in serial column

一曲冷凌霜 提交于 2019-12-11 04:54:47
问题 i am trying to use "unnest" function in insert, while doing so, the serial skips a number for each insert, plz help me to solve this... mydb=# \d tab1 Table "public.tab1" Column | Type | Modifiers --------+---------+--------------------------------------------------- id | integer | not null default nextval('tab1_id_seq'::regclass) col1 | integer | col2 | integer | Indexes: "tab1_pkey" PRIMARY KEY, btree (id) mydb=# insert into tab1(id,col1,col2) values (nextval('tab1_id_seq'),1,unnest(array[4

How can I find out which rows have been deleted?

泪湿孤枕 提交于 2019-12-11 04:49:35
问题 Informix-SQL 7.32 with SE engine: I have a customer who deleted several rows from an SE table. (I'm not using transaction logging or audit). The table has a serial column. I would like to create an Ace report to print the missing serial columns. I tried the following quick and dirty report, but it didn't work!.. can you suggest a better way? define variable next_id integer end select tbl_id from tbl order by tbl_id {I'm ordering tbl_id because all the rows are periodically re-clustered} end

The variable inside while loop is not remembered. Mysql bash script auto_increment

妖精的绣舞 提交于 2019-12-11 04:46:11
问题 I've working on this script for quite some time. But I started to see some errors when I tried to add a variable ($EMAIL_MSG) to store some strings of text to later be emailed. It seems that the variable inside while loop is not remembered. (A variable modified inside a while loop is not remembered) Here is part of the script: #!/bin/bash # # This is bash script checks when auto_increment column is reaching its limit # To run Script $ ./auto_increment_check.sh [username] [password] MYSQL_USER