alter-table

Renaming multiple columns in one statement with PostgreSQL

戏子无情 提交于 2019-11-30 14:31:17
问题 Is it possible to rename multiple columns in a single statement, something along the lines of: ALTER TABLE Users RENAME COLUMN userName TO user_name, RENAME COLUMN realName TO real_name; 回答1: No. While other actions can be combined, that's not possible with RENAME . The manual: All the forms of ALTER TABLE that act on a single table, except RENAME , SET SCHEMA , ATTACH PARTITION , and DETACH PARTITION can be combined into a list of multiple alterations to be applied together. Since RENAME is

Renaming multiple columns in one statement with PostgreSQL

女生的网名这么多〃 提交于 2019-11-30 10:54:37
Is it possible to rename multiple columns in a single statement, something along the lines of: ALTER TABLE Users RENAME COLUMN userName TO user_name, RENAME COLUMN realName TO real_name; No. While other actions can be combined, that's not possible with RENAME . The manual: All the forms of ALTER TABLE that act on a single table, except RENAME , SET SCHEMA , ATTACH PARTITION , and DETACH PARTITION can be combined into a list of multiple alterations to be applied together. Since RENAME is a tiny operation on a system catalog, there is no harm in running multiple statements. Do it in a single

Drop column doesn't remove column references entirely - postgresql

邮差的信 提交于 2019-11-30 10:01:36
问题 I have a table that contained 1600 columns and would like to add more fields in that but as per the database rule the more fields not allowed to be created because the higher limit reached. So I decided to drop few unwanted fields from the table and I did it. Again I tried to add few fields in that table but it's raise the same error that 1600 columns are there you can't add more. I gone through other tables of postgresql " pg_attribute " and all those fields are there and having delete

Warning: A long semaphore wait

房东的猫 提交于 2019-11-30 08:32:52
For the past 4 days I have had massive problems with my nightly updates , except for 1 night were it all went fine in between these 4 days. During these updates i update a couple of fulltext indexes. I do it in this manner. Drop the fulltext index Update the fulltext table Add the fulltext index This has been working perfect for over 2 years . Usual update time was around 3-4 hours which was normal for the amount of data that is updated each night. But since Friday really the update times has been between 9-12 hours! Last night the server crashed intentionally by the engine, this was in the

How do I alter my existing table to create a range partition in Oracle

时光总嘲笑我的痴心妄想 提交于 2019-11-30 03:27:46
问题 I have existing table which has 10 years of data (I have taken dump). I would like to Range partition the existing table on one date key column within the table. Most of the examples I see are with CREATE TABLE..PARTITION BY RANGE... to add new partitions. But my table is existing table. I assume I need some ALTER statement. ALTER TABLE TABLE_NAME PARTITION BY RANGE(CREATED_DATE) PARTITION JAN16 VALUES LESS THAN (01-02-2016), PARTITION FEB16 VALUES LESS THAN (01-03-2016) AND GREATER THAN(31

Add constraint to existing SQLite table

泪湿孤枕 提交于 2019-11-30 01:42:27
问题 I'm using SQLite, which doesn't support adding a constraint to an existing table. So I can't do something like this (just as an example): ALTER TABLE [Customer] ADD CONSTRAINT specify_either_phone_or_email CHECK (([Phone] IS NOT NULL) OR ([Email] IS NOT NULL)); Are there any workarounds for this scenario? I know: I can add a constraint for a new table, but it isn't new (and it's generated by my ORM, EF Core) I can do a "table rebuild" (rename table, create new one, copy old data, drop temp

insert a NOT NULL column to an existing table

≡放荡痞女 提交于 2019-11-29 20:54:49
I have tried: ALTER TABLE MY_TABLE ADD STAGE INT NOT NULL; But it gives this error message: ALTER TABLE only allows columns to be added that can contain nulls or have a DEFAULT definition specified As an option you can initially create Null-able column, then update your table column with valid not null values and finally ALTER column to set NOT NULL constraint: ALTER TABLE MY_TABLE ADD STAGE INT NULL GO UPDATE MY_TABLE SET <a valid not null values for your column> GO ALTER TABLE MY_TABLE ALTER COLUMN STAGE INT NOT NULL GO Another option is to specify correct default value for your column:

How to delete a column from a table in MySQL

和自甴很熟 提交于 2019-11-29 19:02:39
Given the table created using: CREATE TABLE tbl_Country ( CountryId INT NOT NULL AUTO_INCREMENT, IsDeleted bit, PRIMARY KEY (CountryId) ) How can I delete the column IsDeleted ? ALTER TABLE tbl_Country DROP COLUMN IsDeleted; Here's a working example. Note that the COLUMN keyword is optional, as MySQL will accept just DROP IsDeleted . Also, to drop multiple columns, you have to separate them by commas and include the DROP for each one. ALTER TABLE tbl_Country DROP COLUMN IsDeleted, DROP COLUMN CountryName; This allows you to DROP , ADD and ALTER multiple columns on the same table in the one

Drop column doesn't remove column references entirely - postgresql

对着背影说爱祢 提交于 2019-11-29 18:50:37
I have a table that contained 1600 columns and would like to add more fields in that but as per the database rule the more fields not allowed to be created because the higher limit reached. So I decided to drop few unwanted fields from the table and I did it. Again I tried to add few fields in that table but it's raise the same error that 1600 columns are there you can't add more. I gone through other tables of postgresql " pg_attribute " and all those fields are there and having delete parameter = True. What I have tried so far Drop Constraints Take table data into another table Truncate

Alter a live table to make a key non-unique

匆匆过客 提交于 2019-11-29 13:29:14
I saw some other questions related to this, but they were not MySQL. The database is a live database, so I don't want to delete and recreate the table. I simply want to make a column no longer unique, which is less permissive in nature so it shouldn't cause any problems. If your column was defined unique using UNIQUE clause, then use: ALTER TABLE mytable DROP INDEX constraint_name , or, if your constraint was implicitly named, ALTER TABLE mytable DROP INDEX column_name If it was defined unique using PRIMARY KEY clause, use: ALTER TABLE mytable DROP PRIMARY KEY Note, however, that if your table