alter-table

Need steps for Alter the table

Whenever I make changes to a table structure in SSMS, there is a alert raised: saving the changes is not permitted.the changes u have been made to the following tables to be dropped and recreate.. ...

Alter MYSQL Table To Add Comments on Columns

I have been checking the MySql Documentation for Alter Table and it does not seem to include a way to Alter a MySQL Table for adding a comment for the columns. Anybody knows how can i do it? thanks // for table ALTER TABLE myTable COMMENT 'Hello World' // for columns // ??? ...

Mysql - Alter a column to be AUTO_INCREMENT

I'm trying to modify a table to make it's primary key column AUTO_INCREMENT after the fact. I have tried the following sql, but got a syntax error: ALTER TABLE document ALTER COLUMN document_id AUTO_INCREMENT Am I doing something wrong or is this not possible? +--------------------+ | VERSION() | +--------------------+ | 5...

SQLite3 and Alter table .. after ..

Is there a simple way to modify a table in recent sqlite versions so that it matches a predefined schema? Schema: war_id INTEGER NOT NULL, clanname VARCHAR(64), clanhomepage VARCHAR(128), date DATETIME, server VARCHAR(64), warmode_id INTEGER, squad_id INTEGER, notes TEXT, clantag String(16), PRIMARY KEY (war_id), FOREIGN KEY(w...

MySql ALTER TABLE on Production Databases - Any Issues?

I have about 100 databases (all the same structure, just on different servers) with approx a dozen tables each. Most tables are small (lets say 100MB or less). There are occasional edge-cases where a table may be large (lets say 4GB+). I need to run a series of ALTER TABLE commands on just about every table in each database. Mainly addi...

Syntax for Alter Column and Add Column in same query

Is it possible to both alter a column and add a new column in the same alter table query for MSQL? I've tried looking at the below MSDN article, but it was a bit confusing to understand. I could easily do it with multiple queries, but would rather do it with one query if possible. Thanks. http://msdn.microsoft.com/en-us/library/ms19027...

MYSQL Contraints - Multiple Checks

Well i am here writing some constraints for a db I am working on and i was wondering if I could do the following: ALTER TABLE Course ADD CONSTRAINT cs_level CHECK (clevel in ('P','I','II','III')) ...instead of this: ALTER TABLE Course ADD CONSTRAINT cs_level CHECK (clevel = 'P' OR clevel = 'I' OR clevel = 'II' OR clevel = 'III') ...

query " ALTER TABLE test_posts ADD sticky boolean NOT NULL default = false" = error

Whats wrong with my query? ALTER TABLE test_posts ADD sticky boolean NOT NULL default = false #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 '=false' at line 2 ...

Execution time of ALTER COLUMN

Having a table with 60 columns, and 200 rows. Altering a BIT column from NULL to NOT NULL, now has a running execution time of over 3 hours. Why is this taking so long? This is the query that I'm execution: ALTER TABLE tbl ALTER COLUMN col BIT NOT NULL Is there a faster way to do it, besides creating a new column, updating it with va...

SQLite3, "ALTER TABLE" and durability

I'd like to run some ALTER TABLE statements on a sqlite3 database. What happens if the user kills the process or the power is cut while the ALTER TABLE is running? Will the database be left in a corrupt intermediate state? ...

Alter Sql table (Change foreign key to Second primary of the table)

Hi, I've a sql table with a primary key(Auto Incremented) and a foreign key.Now I need to modify the table by modifying the foreign key to second primary key so that its values are not allowed to duplicate. How do i alter my table without affecting the data? Need the sql code. Regards, Vix ...

Unable to drop constraint in sql server 2005 "Could not drop constraint. See previous errors"

I'm trying to drop a constraint on a db table, something like: ALTER TABLE MyTable drop CONSTRAINT FK_MyTable_AnotherTable But the execution just runs and runs. If I stop it I see: Msg 3727, Level 16, State 0, Line 2 Could not drop constraint. See previous errors. Web search throws up various pages but note that the constraint is p...

MySQL foreign key creation with alter table command

I created some tables using MySQL Workbench, and then did forward ‘forward engineer’ to create scripts to create these tables. BUT, the scripts lead me to a number of problems. One of which involves the foreign keys. So I tried creating separate foreign key additions using alter table and I am still getting problems. The code is below (t...

ALTER TABLE my_table ADD @column INT

If i want to use a variable as name of the new column, is this posible in MS SQL? Example that dont work: ALTER TABLE my_table ADD @column INT This worked great for me: EXEC ('ALTER TABLE my_table ADD ' + @column + ' INT') ...

Deleting Duplicates in MySQL

Query was this: CREATE TABLE `query` ( `id` int(11) NOT NULL auto_increment, `searchquery` varchar(255) NOT NULL default '', `datetime` int(11) NOT NULL default '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM first I want to drop the table with: ALTER TABLE `querynew` DROP `id` and then delete the double entries.. I tried it with: INSERT...

SQLite Modify Column

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 ...

Resetting AUTO_INCREMENT on myISAM without rebuilding the table

Please help I am in major trouble with our production database. I had accidentally inserted a key with a very large value into an autoincrement column, and now I can't seem to change this value without a huge rebuild time. ALTER TABLE tracks_copy AUTO_INCREMENT = 661482981 Is super-slow. How can I fix this in production? I can't get ...

How to change a primary key in SQL to auto_increment?

I have a table in MySQL that has a primary key: mysql> desc gifts; +---------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------------+-------------+------+-----+---------+-------+ | giftID | int(11) | NO | PRI | NULL | | | name | v...

Mysql change column details

I am trying to redefine the number of varchars a column can have (in a MySQL db). I am doing alter table obj_details IMG_SRC IMG_SRC varchar(180); I want to change the number of characters that can be used in the column IMG_SRC to 180 (it is currently 100). But I get an error saying that I should check the syntax near IMG_SRC IMG_SR...

How to convert a table column to another data type

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 d...