alter-table

Force Truncation on VARCHAR modification?

℡╲_俬逩灬. 提交于 2019-12-11 11:54:13
问题 I would like to cap VARCHAR to 255 on a few columns so that I can add an index. alter table striker modify contacts varchar(255) When I try to run the above command I get Error Code: 1265. Data truncated for column 'contacts' at row 331 38.969 sec Is there a way to force truncation of the column so that this command successfully shortens the VARCHAR? I don't care about shortening the data in the column. 回答1: You can manually truncate the column at 255 characters: UPDATE striker SET contacts =

ALTER TABLE error

*爱你&永不变心* 提交于 2019-12-11 06:19:18
问题 Can someone explain to me why I am receiving the following error? I want to rename the column "exerciseID" to "ID" in a mysql table using the following syntax. ALTER TABLE `exercises` CHANGE `exerciseID` `ID` INT( 11 ) NOT NULL AUTO_INCREMENT However I receive the following error: MySQL said: #1025 - Error on rename of './balance/#sql-de_110e' to './balance/exercises' (errno: 150) Any suggestions would be much appreciated 回答1: I would check to see if you have any foreign key references to

SQL Server script: ALTER PROCEDURE - Executing multiple ALTER PROCEDURE into one script without having to select each of the ALTER one after another

主宰稳场 提交于 2019-12-11 00:49:05
问题 I know this is not a big issue, but it tickles me anyway. I have a SQL Server 2005 script to create new data tables, constraints, altering some tables to add columns, altering procedures to take the table changes into account, etc. Everything runs fine until the script encounters my ALTER PROCEDURE statements. The error message is as follows: "Msg 156, Level 15, State 1, Procedure cpromo_Get_ConsultDetails_PromotionBan, Line 59 Incorrect syntax near the keyword 'PROCEDURE'. Here's a sample of

Alter AUTO_INCREMENT value by select result

喜欢而已 提交于 2019-12-10 21:17:08
问题 Basically what I want is a working-version of the following code: ALTER TABLE table_name AUTO_INCREMENT = ( SELECT `AUTO_INCREMENT` FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'database_name' AND TABLE_NAME = 'another_table_name' ); The error: 1064 - 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 'AUTO_INCREMENT = The reason: According to MySQL Doc: InnoDB uses the in-memory auto-increment counter

Adding column-name dynamically in alter table

こ雲淡風輕ζ 提交于 2019-12-10 12:30:13
问题 I am developing a web application and need to use ALTER Table in it. Here is my code: ALTER TABLE [tablename] ADD [column-name] [Type] DEFAULT [default-value] NULL/NOT NULL Now i want to change [column-name] dynamically by a text box. How can i do that? In addition i used @name in AddWithValue, but it doesn't work! Can any body help me? Thanks here is my whole code: SqlConnection sqlconn4 = new SqlConnection(ConfigurationManager.ConnectionStrings["dbConn"].ConnectionString); SqlCommand

How to set AUTO_INCREMENT from another table

笑着哭i 提交于 2019-12-10 04:32:18
问题 How can I set the AUTO_INCREMENT on CREATE TABLE or ALTER TABLE from another table? I found this question, but not solved my issue: How to Reset an MySQL AutoIncrement using a MAX value from another table? I also tried this: CREATE TABLE IF NOT EXISTS `table_name` ( `id` mediumint(6) unsigned NOT NULL AUTO_INCREMENT, `columnOne` tinyint(1) NOT NULL, `columnTwo` int(12) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=(SELECT `AUTO_INCREMENT` FROM `INFORMATION

Create column and insert into it within the same transaction?

三世轮回 提交于 2019-12-10 02:09:51
问题 Is it possible to create a column and insert values to it during the same transaction? This is part of an upgrade script. I found the following method online, but it does not work; I get an error: Invalid column name 'IndexNumber'. . I'm assuming this is because the transaction hasn't created the column yet so there is nothing to insert to. The relevant parts of my script: Print 'Beginning Upgrade' Begin Transaction -- -------------------------------------------------------------------- USE

How to convert a table column to another data type

让人想犯罪 __ 提交于 2019-12-09 12:04:28
问题 I have a column with the type of Varchar in my Postgres database which I meant to be integers... and now I want to change them, unfortunately this doesn't seem to work using my rails migration. change_column :table1, :columnB, :integer Which seems to output this SQL: ALTER TABLE table1 ALTER COLUMN columnB TYPE integer So I tried doing this: execute 'ALTER TABLE table1 ALTER COLUMN columnB TYPE integer USING CAST(columnB AS INTEGER)' but cast doesn't work in this instance because some of the

MySQL - Duplicate entry error when trying to add new column

本小妞迷上赌 提交于 2019-12-09 08:04:10
问题 I have a MySQL database with a table that has 2 million rows using innodb engine. I want to add another column, but I keep getting the following error: Error 1062: Duplicate entry '' for key 'PRIMARY' SQL Statement: ALTER TABLE `mydb`.`table` ADD COLUMN `country` VARCHAR(35) NULL DEFAULT NULL AFTER `email` How can I add the column without getting this error? EDIT: Table definition id int(11) NOT NULL AUTO_INCREMENT, user_id varchar(45) NOT NULL, first_name varchar(150) DEFAULT NULL, last_name

Adding column to table & adding data right away to column in PostgreSQL

删除回忆录丶 提交于 2019-12-09 07:00:13
问题 I am trying to create a new column in an existing table, and using a select statement to do division to create the data I want to insert into my new column. Several of the statements I have written out will work as separate queries but I have not been able to string together the statements into one single query. I am still learning SQL and using it with mySQL and PostgreSQL. I took a class last month on SQL and now I am trying to do my own projects to keep my skills sharp. I am doing some