alter

Postgresql - Using subqueries with alter sequence expressions

删除回忆录丶 提交于 2019-11-30 06:04:23
My question is kind of simple. Is it possible to use subqueries within alter expressions in PostgreSQL? I want to alter a sequence value based on a primary key column value. I tried using the following expression, but it wouldn't execute. alter sequence public.sequenceX restart with (select max(table_id)+1 from table) Thanks in advance I don't believe you can do it like that but you should be able to use the setval function direction which is what the alter does. select setval('sequenceX', (select max(table_id)+1 from table), false) The false will make it return the next sequence number as

How to alter MySQL table without losing data?

佐手、 提交于 2019-11-30 03:14:48
问题 In my application, I make some changes and upload them to a testing server. Because I have no access to the server database I run ALTER commands to make changes on it. Using a method I ran the following command on server: ALTER TABLE `blahblahtable` ADD COLUMN `newcolumn` INT(12) NOT NULL After that, I found that the all the data of the table has been removed. Now the table is blank. So I need to alter the table without removing his data. Is there any way to do that? 回答1: Your question is

Alter SQL table - allow NULL column value

不问归期 提交于 2019-11-30 00:38:16
问题 Initially, the table "MyTable" has been defined in the following way: CREATE TABLE IF NOT EXISTS `MyTable` ( `Col1` smallint(6) NOT NULL AUTO_INCREMENT, `Col2` smallint(6) DEFAULT NULL, `Col3` varchar(20) NOT NULL, ); How to update it in such a way that the column "Col 3" would be allowed to be NULL? 回答1: The following MySQL statement should modify your column to accept NULLs. ALTER TABLE `MyTable` ALTER COLUMN `Col3` varchar(20) DEFAULT NULL 回答2: ALTER TABLE MyTable MODIFY Col3 varchar(20)

alter composite primary key in cassandra CQL 3.0

℡╲_俬逩灬. 提交于 2019-11-29 16:04:41
问题 I'm in a situation where I need to change the the composite primary key as follows: Old Primary Key: (id, source, attribute_name, updated_at); New Primary Key I want: (source, id, attribute_name, updated_at); I issued the following (mysql like) command: ALTER TABLE general_trend_table DROP PRIMARY KEY, ADD PRIMARY KEY(source, id, attribute_name, updated_at); I got the following error: Bad Request: line 1:38 no viable alternative at input 'PRIMARY' any idea how to get around this problem? more

Can i undo ALTER table in - MySQL?

怎甘沉沦 提交于 2019-11-29 15:29:40
Don't know if it's possible, I Altered VARCHAR column to Decimal Type which i want to Rollback. Because it blended all floating values as integer. like 2.00 became 200. Is there any way to undo my last table Alteration? Please advise. No, you can't roll back ALTER TABLE statements. https://dev.mysql.com/doc/refman/5.7/en/cannot-roll-back.html Some statements cannot be rolled back. In general, these include data definition language (DDL) statements, such as those that create or drop databases, those that create, drop, or alter tables or stored routines. (emphasis mine) As Chris Peters comments

How to add new column in existing View in SQL-Server 2014 using Alter

浪尽此生 提交于 2019-11-29 10:09:23
I have created a view that is based on another view and a table. I want to add new column of type varchar. I did like below, But getting syntax error? I am new to SQL, So,could not understand ALTER VIEW [dbo].[MyView] ADD New_Col varchar(10) null GO you have to write the entire view again and just add or omit what you want to change for example your view is now : create view myView as select field1 from table1 and now you want to add a field called New_Col than you write this : alter view myView as select field1, New_Col from table1 You can't alter a view like a table. You have to script the

Postgresql - Using subqueries with alter sequence expressions

99封情书 提交于 2019-11-29 04:33:59
问题 My question is kind of simple. Is it possible to use subqueries within alter expressions in PostgreSQL? I want to alter a sequence value based on a primary key column value. I tried using the following expression, but it wouldn't execute. alter sequence public.sequenceX restart with (select max(table_id)+1 from table) Thanks in advance 回答1: I don't believe you can do it like that but you should be able to use the setval function direction which is what the alter does. select setval('sequenceX

How to change the primary key to be non-clustered?

别来无恙 提交于 2019-11-29 02:52:08
Part-time reluctant DBA here. I want to change an existing primary key index from clustered to non-clustered. And the syntax is escaping me. This is how it's scripted out right now. ALTER TABLE [dbo].[Config] WITH NOCHECK ADD CONSTRAINT [PK_Config] PRIMARY KEY CLUSTERED ( [ConfigID] ) ON [PRIMARY] I am not seeing an ALTER CONSTRAINT statement in the online docs. Drop the clustered index, then recreate the primary key as non-clustered: ALTER TABLE dbo.Config DROP CONSTRAINT PK_Config go ALTER TABLE dbo.Config ADD CONSTRAINT PK_Config PRIMARY KEY NONCLUSTERED (ConfigID) 来源: https://stackoverflow

Difficulty in upgrading SQlite table

我的未来我决定 提交于 2019-11-28 16:35:23
I have an application running with a working table called ANIMAL. Upon first creating this table it consisted simply of _id and animal_name columns. Now I am trying to expand on it, including a animal_biography column, however I am having a little difficulty.At first I thought I was just a case of upgrading my CREATE_TABLE statement to include the animal bio: private static final String DATABASE_CREATE = "create table " + ANIMALS_TABLE + " (_id integer primary key autoincrement, " + "animal_name text not null, " + "biography text not null);"; however, looking at the logcat it tells me the

Can i undo ALTER table in - MySQL?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 08:52:18
问题 Don't know if it's possible, I Altered VARCHAR column to Decimal Type which i want to Rollback. Because it blended all floating values as integer. like 2.00 became 200. Is there any way to undo my last table Alteration? Please advise. 回答1: No, you can't roll back ALTER TABLE statements. https://dev.mysql.com/doc/refman/5.7/en/cannot-roll-back.html Some statements cannot be rolled back. In general, these include data definition language (DDL) statements, such as those that create or drop