alter-table

Alter table after keyword in Oracle

丶灬走出姿态 提交于 2019-11-29 09:33:16
ALTER TABLE testTable ADD column1 NUMBER(1) DEFAULT 0 NOT NULL AFTER column2; Why can't I use mySql syntax in Oracle too? The above command works in MySql. Can you give me an equivalent that works? Error report: SQL Error: ORA-01735: invalid ALTER TABLE option 01735. 00000 - "invalid ALTER TABLE option" I am asking if there is any way to use after clause in Oracle command that I provided? Because SQL is a relational algebra. It doesn't care one bit about "where" columns are located within a table, only that they exist. To get it to work in Oracle, just get rid of the after clause. The Oracle

Why can't SQL Server alter a view in a stored procedure?

风格不统一 提交于 2019-11-29 07:37:40
I'm using MS SQL Server, and I'd like to alter a view from within a stored procedure, by executing something like "alter view VIEWNAME as ([some sql])". A few pages thrown up by google assert that this is not supported directly (and neither are related alter-table statements), but there are also examples of how to work around it using constructions like this: declare @sql varchar(max) select @sql = 'alter view VIEWNAME as ([some sql])' exec(@sql) Writing code as literal strings smells a bit, even for SQL. My questions: Why is this not supported? What's the difference between running this from

Add not null DateTime column to SQLite without default value?

纵然是瞬间 提交于 2019-11-29 07:20:26
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 just a plain datetime not null) Instead of using ALTER TABLE ADD COLUMN , create a new table that has the extra column, and copy your old data. This will free you from the restrictions of ALTER TABLE and let you have a NOT NULL constraint without a default value.

How to change VARCHAR type to DATETIME using ALTER in MySQL?

孤街醉人 提交于 2019-11-29 06:24:01
问题 How can I change VARCHAR() type to DATETIME using ALTER in MySQL? 回答1: ALTER TABLE <tblName> MODIFY <columnName> dataType constraint; For your requirement it will be ALTER TABLE <tblName> MODIFY <columnName> datetime; Refer http://dev.mysql.com/doc/refman/5.1/en/alter-table.html 回答2: Try this query. ALTER TABLE `table_name` CHANGE `From Date` `From Date` DATETIME NULL DEFAULT '0000-00-00 00:00:00'; 回答3: Why not you just use STR_TO_DATE(str,format) , It takes a string str and a format string

SQL Server - script to update database columns from varchar to nvarchar if not already nvarchar

北城以北 提交于 2019-11-29 04:08:21
I am in a situation where I must update an existing database structure from varchar to nvarchar using a script. Since this script is run everytime a configuration application is run, I would rather determine if a column has already been changed to nvarchar and not perform an alter on the table. The databases which I must support are SQL Server 2000, 2005 and 2008. The following query should get you what you need: IF EXISTS (SELECT * FROM sysobjects syo JOIN syscolumns syc ON syc.id = syo.id JOIN systypes syt ON syt.xtype = syc.xtype WHERE syt.name = 'nvarchar' AND syo.name = 'MY TABLE NAME'

Add column to table and then update it inside transaction

ぃ、小莉子 提交于 2019-11-28 19:03:51
I am creating a script that will be run in a MS SQL server. This script will run multiple statements and needs to be transactional, if one of the statement fails the overall execution is stopped and any changes are rolled back. I am having trouble creating this transactional model when issuing ALTER TABLE statements to add columns to a table and then updating the newly added column. In order to access the newly added column right away, I use a GO command to execute the ALTER TABLE statement, and then call my UPDATE statement. The problem I am facing is that I cannot issue a GO command inside

Alter column, add default constraint

亡梦爱人 提交于 2019-11-28 16:15:57
I have a table and one of the columns is "Date" of type datetime. We decided to add a default constraint to that column Alter table TableName alter column dbo.TableName.Date default getutcdate() but this gives me error: Incorrect syntax near '.' Does anyone see anything obviously wrong here, which I am missing (other than having a better name for the column) Try this alter table TableName add constraint df_ConstraintNAme default getutcdate() for [Date] example create table bla (id int) alter table bla add constraint dt_bla default 1 for id insert bla default values select * from bla also make

MySQL very slow for alter table query

南笙酒味 提交于 2019-11-28 16:11:43
Why is it taking more than an hour to simply update this table to add a column? This table has 15M rows. It has 2 indexes and a single key primary key. The ALTER TABLE query has been in "copy to tmp table" state for 1 hour 15 minutes now. ALTER TABLE `frugg`.`item_catalog_map` ADD COLUMN `conversion_url` TEXT NULL DEFAULT NULL Table: mysql> describe item_catalog_map; +------------------------+---------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------------------+---------------+------+-----+---------+-------+ | catalog_unique_item_id | varchar

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

人走茶凉 提交于 2019-11-28 15:13:50
I am trying to change a column from a varchar(50) to a nvarchar(200) . What is the SQL command to alter this table? cmsjr 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. Don't forget nullability. ALTER TABLE <schemaName>.<tableName> ALTER COLUMN <columnName> nvarchar(200) [NULL|NOT NULL] Use the Alter table statement. Alter table TableName Alter Column ColumnName nvarchar(100) Yogesh Bende The syntax to modify a column in an existing table in SQL Server (Transact-SQL) is: ALTER TABLE

Adding column between two other columns in SQL server

主宰稳场 提交于 2019-11-28 12:19:10
Can you add a column to a table inserting it in between two existing columns in SQL Server without dropping and re-creating the table? The simple answer is no. Is there a reason why column order is important to you? Mediumly long answer, yes (ish) but it's ugly and you probably wouldn't want to do it. please note: this code creates a physical table CREATE TABLE MyTest (a int, b int, d int, e int) INSERT INTO MyTest (a,b,d,e) VALUES(1,2,4,5) SELECT * FROM MyTest ALTER TABLE MyTest ADD c int ALTER TABLE MyTest ADD d_new int ALTER TABLE MyTest ADD e_new int UPDATE MyTest SET d_new = d, e_new = e