alter-table

ALTER TABLE without locking the table?

南笙酒味 提交于 2019-12-17 08:04:05
问题 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

ALTER TABLE without locking the table?

别说谁变了你拦得住时间么 提交于 2019-12-17 08:04:03
问题 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

ALTER TABLE table AUTO_INCREMENT = $x

痞子三分冷 提交于 2019-12-13 02:41:49
问题 i would to execute this query but it doesn't work and i don't know why : $query = mysqli_query($connexionUser, "ALTER TABLE creatik AUTO_INCREMENT = '$i'"); i check my vars and there are okay. Auto increment is set on a id column who is primary key if it can help to understand what's wrong. Thanks to take a look :) 回答1: AUTO_INCREMENT expects an integer. It's possible that the quotes are throwing it off, try removing them. 来源: https://stackoverflow.com/questions/12588071/alter-table-table

Will changing column from timestamp to timestamptz lock the table?

半腔热情 提交于 2019-12-12 20:06:30
问题 I want to migrate a column from timestamp (no timezone) to timestamptz type. I'm on Postgres 9.3.9. I need to know if this operation will cause a table rewrite (lock the table) as my table is large and the db is live. I found this in the 9.2 release notes: Increasing the length limit for a varchar or varbit column, or removing the limit altogether, no longer requires a table rewrite. Similarly, increasing the allowable precision of a numeric column, or changing a column from constrained

SQL Alter Table then Modify Values

断了今生、忘了曾经 提交于 2019-12-12 15:18:44
问题 I have a SQL script that I am working on and I run into an issue when I'm creating (or editing) a column and then attempting to modify that new column. For example: BEGIN ALTER TABLE SampleTable ADD ColumnThree int END IF (EXISTS (SELECT * FROM sys.columns WHERE name = 'ColumnThree')) BEGIN UPDATE SampleTable SET ColumnThree = 0 END Now I thought the BEGIN/END blocks would separate those two items out, but I get an error "Invalid column name 'ColumnThree'." when I attempt to run this. Why?

adding multiple columns via a loop in postgresql

谁说胖子不能爱 提交于 2019-12-12 04:54:49
问题 I'm trying to create a new table in a schema that has multiple columns, named via an index. CREATE TABLE rflux (pk SERIAL PRIMARY KEY NOT NULL); Now I want to add new columns like col0 FLOAT, col1, col2, col3, .... up to colN. I know I can do something like ALTER TABLE rflux add column col0 FLOAT add column col1 FLOAT ... ; but I don't want to type everything out, since I need to create ~4500 columns. I'm trying to implement this with loops but I can't quite get it working. Does anyone have

SQL: Add a new column based on CASE expression and looking up values from another table

丶灬走出姿态 提交于 2019-12-12 04:03:24
问题 I am trying to add a new column called Multiplier to an existing table called Trades. The row values of this column will depend on another column on the Trades table called Type. If the Type is anything other than "Equity", "Corp" or "Option, then the value needs to be looked up from another table called ContractSize. Lastly, I want the data type of the Multiplier column to be decimal (7,3). The code I had was: ALTER TABLE Portfolio.Trades ADD Multiplier decimal(7,3) AS ( CASE WHEN Type =

Why is my alter table statement not properly adding a column to my temporary table?

≯℡__Kan透↙ 提交于 2019-12-12 01:59:52
问题 I have a temporary table created at the beginning of this stored procedure. It is created successfully and can be selected from and inserted to. Here is the create statement CREATE TABLE #tmpImportData (GuideFirstName VARCHAR(MAX), GuideLastName VARCHAR(MAX), email VARCHAR(MAX), group_id_text VARCHAR(MAX), CandidateName VARCHAR(MAX), grade_text VARCHAR(5), dateofbirth DATE ) My problem is trying to update a column after I alter the temporary table. I get the error Msg 207, Level 16, State 1

Move Tables & Revoke All Privileges

安稳与你 提交于 2019-12-11 17:39:45
问题 We need users to move their tables from their personal schemas (user_db.username) to the managed schema (userdb.groupname) which provides a predefined set of permissions for select access. In moving the table, we need to accomplish the following: Move the table out of the old schema Remove the old select grants Apply the new grants from the managed schema I've reviewed the Alter table .. rename to.. documentation, and while that appears to enable movement of the table, it would retain the old

PHP Script to fix MySQL columns to work with strict-mode

こ雲淡風輕ζ 提交于 2019-12-11 16:04:34
问题 I'm trying to build a script to generate ALTER TABLE queries so that across whole schemas, columns are adjusted to be compatible with MySQL strict-mode.. I want it to be a simple as possible, making the most basic changes possible for NOT/NOT NULL and Default values to ensure strict-mode compatibility, but at the same time minimising the chances of breaking any existing queries, or associated PHP code that depends on the schema definition's workings. Any tips / things I've missed out / things