alter-table

I need to alter a sqlite3 table to add FTS3

I need the ability to add FTS3 to a sqlite3 table after it was created, not as it is created. Does anyone know the ALTER syntax to accomplish this? ...

ALTER TABLE error

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 './balan...

T-SQL Add Column In Specific Order

Im a bit new to T-SQL, Coming from a MySQL background Im still adapting to the different nuances in the syntax. Im looking to add a new column AFTER a specific one. I've found out that AFTER is a valid keyword but I don't think it's the right one for the job. ALTER TABLE [dbo].[InvStockStatus] ADD [Abbreviation] [nvarchar](32) DEFAULT ...

How do I drop 'NOT NULL' from a column in MySQL?

A show create table command shows the following: 'columnA' varchar(6) NOT NULL DEFAULT ''; How do I modify that column so that the not null is removed? I need it to be: 'columnA' varchar(6) DEFAULT NULL; I thought the following would work, but it has no effect: ALTER TABLE tbl_name MODIFY columnA varchar(6) DEFAULT NULL; ...

Add a column and update it in same stored procedure in SQL Server 2008

if I have a stored procedure say CREATE PROCURE w AS ALTER TABLE t ADD x char(1) UPDATE t set x =1 Even when it lets me create that stored procedure (if I create it when x exists), when it runs, there is an error on the UPDATE statement because column x doesn't exist. What's the conventional way to deal with this, it must come up a...

Add not null DateTime column to SQLite without default value?

It looks like i cant add a not null constraint or remove a default constraint. I would like to add a datetime column to a table and have all the values set to anything (perhaps 1970 or year 2000) but it seems like i cant use not null without a default and i cant remove a default once added in. So how can i add this column? (once again ju...

SQL: ATER COLUMN to shorter CHAR(n) type

I'm working with MS SQL SERVER 2003. I want to change a column in one of my tables to have fewer characters in the entries. This is identical to this question: http://stackoverflow.com/questions/2281336/altering-a-table-column-to-accept-more-characters except for the fact that I want fewer characters instead of more. I have a column i...

How to add a default value to an already existing column?

I have an existing column in my SQL Server database. I have tried about everything I can think of but can not get a default value to be added to the column. What works in every other database is alter table mytable alter column mycolumn set default(now()) --mycolumn is a datetime How do I do this in SQL Server? The error I get f...

SQL Error Alter Table?

I have been trying to add columns to a table using some logic that produces this statement: ALTER TABLE Master_List ADD COLUMN Service VARCHAR(100) , Vendor VARCHAR(100) , Product VARCHAR(100) , Service_Description VARCHAR(100) , Level/Scale VARCHAR(100) , SunGard_...

How do I ALTER a set of partitioned tables in Postgres?

I created a set of partitioned tables in Postgres, and started inserting a lot of rows via the master table. When the load process blew up on me, I realized I should have declared the id row BIGSERIAL (BIGINT with a sequence, behind the scenes), but inadvertently set it as SERIAL (INTEGER). Now that I have a couple of billion rows loaded...

SQL Server - Change a Nullable column to NOT NULL with Default Value

Hey everyone, I came across an old table today with a datetime column called 'Created' which allows nulls. Now, I'd want to change this so that it is NOT NULL, and also include a constraint to add in a default value (getdate()). So far I've got the following script, which works fine provided that i've cleaned up all the nulls beforeha...

MySQL: How to add a column if it doesn't already exist?

I want to add a column to a table, but I don't want it to fail if it has already been added to the table. How can I achieve this? # Add column fails if it already exists ALTER TABLE `TableName` ADD `ColumnName` int(1) NOT NULL default '0'; ...

Problem with Postgres ALTER TABLE

Hi, I have one problem with the ALTER TABLE in postgre. I want to change size of the varchar column. When I try to do this, It says that the view is dependent on that column. I can't drop the view because comething else is dependent on it. Is there any other way than to drop everything and recreate it again? I just found one option, whi...

search simple way to alter multi tables in one time in mysql

i have a lot of tables that start with some prefix , and i want to alter this tables what is the simple way to do this (instead run over all tables) i mean something like : ALTER TABLE LIKE tablenameprefix% ADD INDEX `NewIndex1` (`field`); how can i do this ? thanks EDIT : can i do a kind of loop not in stored procedure ? by...

MySQL triggers alteration

Is there any way how to update automatically mysql trigger(s) structure, every time when I alter a table? ...

Alter Table in SQL Server Transaction

I'm trying to write this transaction where I'm trying to add a column to a table using TRY..CATCH and TRANSACTION. Here's my code. But the problem is the column already exists in the table and the catch block should execute, but the catch block is not executing and the transaction is not being rolled back and also the select error_number...

Alter Table Set unique problem on postgres

I am using Postgres as DBMS and Django. My model that defines the table is: class TtnetModem(models.Model): ttnetModemSerino=models.CharField(_(u"Seri No"), max_length=20, default='', null=True, blank=True) I change field definition... ttnetModemSerino=models.CharField(_(u"Seri No"), max_length=20, unique= True) on postgres, i ex...

alter table add ... before `code`?

Hi there, ALTER TABLE `tada_prod`.`action_6_weekly` ADD COLUMN `id` INT NULL AUTO_INCREMENT UNIQUE AFTER `member_id`; works, so i thought, to add the column as the first column i could do ALTER TABLE `tada_prod`.`action_6_weekly` ADD COLUMN `id` INT NULL AUTO_INCREMENT UNIQUE BEFORE `code`; but i get a syntax error, what ...

MYSQL alter table - add INDEX + FOREIGN KEY give error 1005

what is wrong with this alter table command : ALTER TABLE `lp` ADD COLUMN `RuleId` INT(10) NOT NULL DEFAULT -111 AFTER `Weight` , , ADD CONSTRAINT `fk_1` FOREIGN KEY (`RuleId` ) REFERENCES `Rules` (`RuleId` ) ON DELETE NO ACTION ON UPDATE NO ACTION, ADD INDEX `fk_1` (`RuleId` ASC) ; if i drop the line ADD CONSTRAINT `fk_1` FORE...

Column creation and use

Hi, I am fairly new to SQL, so not sure if this is just a SQL compiler thing or not. When I have used SQL before it's been through JAVA or PHP, never just straight SQL. I am using SQL Server 2005 and attempting to add a column to my table, and then populate it. Here is what I have now: ALTER TABLE House DROP COLUMN CustomerType ALTE...