alter-table

ALTER table - adding AUTOINCREMENT in MySQL

寵の児 提交于 2019-11-27 17:47:28
I created a table in MySQL with on column itemID . After creating the table, now I want to change this column to AUTOINCREMENT . How can this be done using ALTER statements? Table definition: ALLITEMS (itemid int(10) unsigned, itemname varchar(50)) I am using the following code but it is throwing error: syntax incorrect . ALTER TABLE allitems MODIFY itemid INT(10) UNSIGNED AUTOINCREMENT; ThinkCode CREATE TABLE ALLITEMS( itemid INT(10)UNSIGNED, itemname VARCHAR(50) ); ALTER TABLE ALLITEMS CHANGE itemid itemid INT(10)AUTO_INCREMENT PRIMARY KEY; DESC ALLITEMS; INSERT INTO ALLITEMS(itemname)

How to change MySQL column definition?

断了今生、忘了曾经 提交于 2019-11-27 17:15:56
I have a mySQL table called test: create table test( locationExpect varchar(120) NOT NULL; ); I want to change the locationExpect column to: create table test( locationExpect varchar(120); ); How can it be done quickly? mikej Do you mean altering the table after it has been created? If so you need to use alter table , in particular: ALTER TABLE tablename MODIFY COLUMN new-column-definition e.g. ALTER TABLE test MODIFY COLUMN locationExpect VARCHAR(120); Niranjan Vaddi Syntax to change column name in MySql : alter table table_name change old_column_name new_column_name data_type(size); Example:

Create an index on a huge MySQL production table without table locking

陌路散爱 提交于 2019-11-27 17:02:38
I need to create an index on a ~5M rows MySQL table. It is a production table, and I fear a complete block of everything if I run a CREATE INDEX statement... Is there a way to create that index without blocking inserts and selects? Just wondering I have not to stop, create index and restart my system! [2017] Update: MySQL 5.6 has support for online index updates https://dev.mysql.com/doc/refman/5.6/en/innodb-create-index-overview.html In MySQL 5.6 and higher, the table remains available for read and write operations while the index is being created or dropped. The CREATE INDEX or DROP INDEX

SQLite Modify Column

时光总嘲笑我的痴心妄想 提交于 2019-11-27 12:34:21
I need to modify a column in a SQLite database but I have to do it programatically due to the database already being in production. From my research I have found that in order to do this I must do the following. Create a new table with new schema Copy data from old table to new table Drop old table Rename new table to old tables name That seems like a ridiculous amount of work for something that should be relatively easy. Is there not an easier way? All I need to do is change a constraint on a existing column and give it a default value. That's one of the better-known drawbacks of SQLite (no

MySQL: ALTER IGNORE TABLE ADD UNIQUE, what will be truncated?

旧时模样 提交于 2019-11-27 07:26:11
I have a table with 4 columns: ID, type, owner, description. ID is AUTO_INCREMENT PRIMARY KEY and now I want to: ALTER IGNORE TABLE `my_table` ADD UNIQUE (`type`, `owner`); Of course I have few records with type = 'Apple' and owner = 'Apple CO'. So my question is which record will be the special one to stay after that ALTER TABLE, the one with smallest ID or maybe the one with biggest as the latest inserted? Galz The first record will be kept, the rest deleted §§ : IGNORE is a MySQL extension to standard SQL. It controls how ALTER TABLE works if there are duplicates on unique keys in the new

Optimizing MySQL for ALTER TABLE of InnoDB

无人久伴 提交于 2019-11-27 07:15:38
Sometime soon we will need to make schema changes to our production database. We need to minimize downtime for this effort, however, the ALTER TABLE statements are going to run for quite a while. Our largest tables have 150 million records, largest table file is 50G. All tables are InnoDB, and it was set up as one big data file (instead of a file-per-table). We're running MySQL 5.0.46 on an 8 core machine, 16G memory and a RAID10 config. I have some experience with MySQL tuning, but this usually focusses on reads or writes from multiple clients. There is lots of info to be found on the

Modify a Column's Type in sqlite3

让人想犯罪 __ 提交于 2019-11-27 06:53:05
I'm pretty new to SQLite 3 and just now I had to add a column to an existing table I had. I went about doing that by doing: ALTER TABLE thetable ADD COLUMN category; . Of course, I forgot to specify that column's type. The first thing I was thinking about doing was dropping that column and then re-adding it. However, it seems that SQLite does not have a simple way of doing this, and I would have had to backup the table and re-create it without the column. This seems messy, and I was wondering if there were just a way of modifying/adding a column's type. I would imagine so, but my searching

sqlite alter table add MULTIPLE columns in a single statement

送分小仙女□ 提交于 2019-11-27 06:28:14
Is it possible to alter table add MULTIPLE columns in a single statement in sqlite? The following would not work. alter table test add column mycolumn1 text, add column mycolumn2 text; mu is too short No, you have to add them one at a time. See the syntax diagram at the top of SQLite's ALTER TABLE documentation : There's no loop in the ADD branch so no repetition is allowed. alter table test add column mycolumn1 text; alter table test add column mycolumn2 text; use the above redifined query 来源: https://stackoverflow.com/questions/6172815/sqlite-alter-table-add-multiple-columns-in-a-single

Alter MySQL table to add comments on columns

混江龙づ霸主 提交于 2019-11-27 06:15:22
I have been checking the MySQL Documentation for ALTER TABLE and it does not seem to include a way to add or modify a comment to a column. How can I do this? -- for table ALTER TABLE myTable COMMENT 'Hello World' -- for columns -- ??? try: ALTER TABLE `user` CHANGE `id` `id` INT( 11 ) COMMENT 'id of user' You can use MODIFY COLUMN to do this. Just do... ALTER TABLE YourTable MODIFY COLUMN your_column your_previous_column_definition COMMENT "Your new comment" substituting: YourTable with the name of your table your_column with the name of your comment your_previous_column_definition with the

ALTER TABLE without locking the table?

一世执手 提交于 2019-11-27 05:56:45
When doing an ALTER TABLE statement in MySQL, the whole table is read-locked for the duration of the statement. If it's a big table, that means insert or update statements could be locked for a looooong time. Is there a way to do a "hot alter", like adding a column in such a way that the table is still updatable throughout the process? Mostly I'm interested in a solution for MySQL but I'd be interested in other RDBMS if MySQL can't do it. To clarify, my purpose is simply to avoid downtime when a new feature that requires an extra table column is pushed to production. Any database schema will