alter-table

Rename column SQL Server 2008

我的梦境 提交于 2019-11-26 19:17:04
I am using SQL Server 2008 and Navicat. I need to rename a column in a table using SQL. ALTER TABLE table_name RENAME COLUMN old_name to new_name; This statement doesn't work. Habib Use sp_rename EXEC sp_RENAME 'TableName.OldColumnName' , 'NewColumnName', 'COLUMN' See: SQL SERVER – How to Rename a Column Name or Table Name Documentation: sp_rename (Transact-SQL) For your case it would be: EXEC sp_RENAME 'table_name.old_name', 'new_name', 'COLUMN' Remember to use single quotes to enclose your values. Alternatively to SQL , you can do this in Microsoft SQL Server Management Studio. Here are a

How to change MySQL column definition?

那年仲夏 提交于 2019-11-26 18:54:41
问题 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? 回答1: 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); 回答2: Syntax to change column name in

Error renaming a column in MySQL

别说谁变了你拦得住时间么 提交于 2019-11-26 18:09:29
How do I rename a column in table xyz ? The columns are: Manufacurerid, name, status, AI, PK, int I want to rename to manufacturerid I tried using PHPMyAdmin panel, but I get this error: MySQL said: Documentation #1025 - Error on rename of '.\shopping\#sql-c98_26' to '.\shopping\tblmanufacturer' (errno: 150) Matt Diamond Lone Ranger is very close... in fact, you also need to specify the datatype of the renamed column. For example: ALTER TABLE `xyz` CHANGE `manufacurerid` `manufacturerid` INT; Remember : Replace INT with whatever your column data type is (REQUIRED) Tilde/ Backtick (`) is

SQLite Modify Column

隐身守侯 提交于 2019-11-26 16:04:06
问题 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

How do I alter the position of a column in a PostgreSQL database table?

牧云@^-^@ 提交于 2019-11-26 15:44:16
问题 I've tried the following, but I was unsuccessful: ALTER TABLE person ALTER COLUMN dob POSITION 37; 回答1: "Alter column position" in the PostgreSQL Wiki says: PostgreSQL currently defines column order based on the attnum column of the pg_attribute table. The only way to change column order is either by recreating the table, or by adding columns and rotating data until you reach the desired layout. That's pretty weak, but in their defense, in standard SQL, there is no solution for repositioning

How do you change the datatype of a column in SQL Server?

徘徊边缘 提交于 2019-11-26 15:05:59
问题 I am trying to change a column from a varchar(50) to a nvarchar(200) . What is the SQL command to alter this table? 回答1: ALTER TABLE TableName ALTER COLUMN ColumnName NVARCHAR(200) [NULL | NOT NULL] EDIT As noted NULL/NOT NULL should have been specified, see Rob's answer as well. 回答2: Don't forget nullability. ALTER TABLE <schemaName>.<tableName> ALTER COLUMN <columnName> nvarchar(200) [NULL|NOT NULL] 回答3: Use the Alter table statement. Alter table TableName Alter Column ColumnName nvarchar

Alter a MySQL column to be AUTO_INCREMENT

给你一囗甜甜゛ 提交于 2019-11-26 14:58:01
I’m trying to modify a table to make its primary key column AUTO_INCREMENT after the fact. I have tried the following SQL, but got a syntax error notification. ALTER TABLE document ALTER COLUMN document_id AUTO_INCREMENT Am I doing something wrong or is this not possible? +--------------------+ | VERSION() | +--------------------+ | 5.0.75-0ubuntu10.2 | +--------------------+ ALTER TABLE document MODIFY COLUMN document_id INT auto_increment Roland Bouman Roman is right, but note that the auto_increment column must be part of the PRIMARY KEY or a UNIQUE KEY (and in almost 100% of the cases, it

Altering a column: null to not null

自古美人都是妖i 提交于 2019-11-26 13:52:55
I have a table that has several nullable integer columns. This is undesirable for several reasons, so I am looking to update all nulls to 0 and then set these columns to NOT NULL . Aside from changing nulls to 0 , data must be preserved. I am looking for the specific SQL syntax to alter a column (call it ColumnA ) to " not null ". Assume the data has been updated to not contain nulls. Using SQL server 2000 . mdb First, make all current NULL values disappear: UPDATE [Table] SET [Column]=0 WHERE [Column] IS NULL Then, update the table definition to disallow NULLs: ALTER TABLE [Table] ALTER

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

∥☆過路亽.° 提交于 2019-11-26 13:09:34
问题 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? 回答1: The first record will be kept, the rest deleted §§: IGNORE is a MySQL

Optimizing MySQL for ALTER TABLE of InnoDB

好久不见. 提交于 2019-11-26 13:08: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