alter

PostgreSQL修改列与重写表

99封情书 提交于 2019-12-11 13:43:04
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 老版本的PostgreSQL在新增列时,会rewrite全表,相当于vacuum full table_name。这对生产是非常不利的,严重导致读写效率的低下。高版本已经有所改善,下面检验之。 检查有没有rewrite表,可以查看它的系统列ctid的变化来验证。 DB:PostgreSQL 9.1.2 postgres=# \d tab_kenyon Table "public.tab_kenyon" Column | Type | Modifiers --------+-----------------------+----------- id | integer | name | character varying(35) | remark | text | 验证过程如下: postgres=# vacuum full tab_kenyon; VACUUM postgres=# select ctid,* from tab_kenyon ; ctid | id | name | remark -------+----+--------------+-------- (0,1) | 1 | kenyon | (0,2) | 2 | china | (0,3) | 5 | oopoo | (0,4) | 45

SQL Server script: ALTER PROCEDURE - Executing multiple ALTER PROCEDURE into one script without having to select each of the ALTER one after another

主宰稳场 提交于 2019-12-11 00:49:05
问题 I know this is not a big issue, but it tickles me anyway. I have a SQL Server 2005 script to create new data tables, constraints, altering some tables to add columns, altering procedures to take the table changes into account, etc. Everything runs fine until the script encounters my ALTER PROCEDURE statements. The error message is as follows: "Msg 156, Level 15, State 1, Procedure cpromo_Get_ConsultDetails_PromotionBan, Line 59 Incorrect syntax near the keyword 'PROCEDURE'. Here's a sample of

Oracle 11g - add new column and set as unique

瘦欲@ 提交于 2019-12-10 20:15:54
问题 I am facing a problem on how to set a new column to unique using Oracle 11g. I try to use this code but it getting error: ALTER TABLE QAS_ASSIGNED_STATE ADD UNIQUE (cuid); 回答1: You should define column's type. Like this: alter table QAS_ASSIGNED_STATE add cuid number NULL; and then add constraint: ALTER TABLE QAS_ASSIGNED_STATE ADD CONSTRAINT constraint_cuid UNIQUE (cuid ); 来源: https://stackoverflow.com/questions/36030261/oracle-11g-add-new-column-and-set-as-unique

Change mysql field name in a huge table

隐身守侯 提交于 2019-12-10 14:12:10
问题 I have a table with 21 million row.I have to change one of the row name.When I try with the query "alter table company change id new_id int(11)"; query never ends. Is there a simple way to change big mysql table's field name? 回答1: First, before anything, backup the table: mysqldump -uroot -p db big_table > /tmp/big_table.backup.sql One thing to keep in mind when doing an ALTER command is to absolutely make sure that you have the same column details for the alter that you would like to not

Difference between Alter and Update SQL [closed]

安稳与你 提交于 2019-12-09 05:01:07
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I am busy studying MySQL and I understand that update is used to update a record or row in a table. So what does alter do that is so different? Seems like they are the same. Thanks, any help will be appreciated.

ALTER TABLE Sqlite: how to check if a column exists before alter the table?

那年仲夏 提交于 2019-12-08 23:58:40
问题 I need to execute in python a SQL query that adds a new column, in sqlite3. The problem is that sometimes it already exists. So previous to executing the query I need to check if the column already exists. If it does, then I won't execute the query. Is there a way in sqlite to do that? Or do I have to make it through a try-catch block in python code? Thanks a lot in advance! 回答1: You can get a list of columns for a table via the following statement: PRAGMA table_info('table_name'); More

MySQL之alter语句用法总结

若如初见. 提交于 2019-12-07 19:02:31
1:删除列 ALTER TABLE 【表名字】 DROP 【列名称】 2:增加列 ALTER TABLE 【表名字】 ADD 【列名称】 INT NOT NULL COMMENT '注释说明' 3:修改列的类型信息 ALTER TABLE 【表名字】 CHANGE 【列名称】【新列名称(这里可以用和原来列同名即可)】 BIGINT NOT NULL COMMENT '注释说明' 4:重命名列 ALTER TABLE 【表名字】 CHANGE 【列名称】【新列名称】 BIGINT NOT NULL COMMENT '注释说明' 5:重命名表 ALTER TABLE 【表名字】 RENAME 【表新名字】 6:删除表中主键 Alter TABLE 【表名字】 drop primary key 7:添加主键 ALTER TABLE sj_resource_charges ADD CONSTRAINT PK_SJ_RESOURCE_CHARGES PRIMARY KEY (resid,resfromid) 8:添加索引 ALTER TABLE sj_resource_charges add index INDEX_NAME (name); 9: 添加唯一限制条件索引 ALTER TABLE sj_resource_charges add unique emp_name2

alter hive multiple column

懵懂的女人 提交于 2019-12-07 14:26:13
问题 How do we alter the datatype of multiple columns in Hive ? CREATE TABLE test_change (a int, b int, c int); ALTER TABLE test_change CHANGE a a string b b doube c c decimal(11,2); 回答1: As far as I know, you can't. In the Hive documentation you can find the following: ALTER TABLE table_name [PARTITION partition_spec] CHANGE [COLUMN] col_old_name col_new_name column_type [COMMENT col_comment] [FIRST|AFTER column_name] [CASCADE|RESTRICT]; This command will allow users to change a column's name,

alter column from time with time zone to timestamp

痴心易碎 提交于 2019-12-07 10:22:03
问题 I am having trouble changing a column called end_date in a table called key_request from time with time zone to timestamp in my Postgres database . I have tried using the following code: alter table key_request alter column end_date type timestamp with time zone using end_date::timestamp with time zone I keep getting the following error: ERROR: cannot cast type time with time zone to timestamp with time zone Any idea of how I can adjust this query to work? 回答1: I woul do this in a series of

Change column name without recreating the MySQL table

此生再无相见时 提交于 2019-12-07 02:00:02
问题 Is there a way to rename a column on an InnoDB table without a major alter? The table is pretty big and I want to avoid major downtime. 回答1: Renaming a column (with ALTER TABLE ... CHANGE COLUMN ) unfortunately requires MySQL to run a full table copy. Check out pt-online-schema-change. This helps you to make many types of ALTER changes to a table without locking the whole table for the duration of the ALTER. You can continue to read and write the original table while it's copying the data