alter-table

SQL alter column datatype from nvarchar to int

北慕城南 提交于 2020-06-11 16:51:28
问题 Can the datatype of a field be changed to int from nvarchar?? alter table employee alter column designation int is this valid?? If not can it be done in some other way?? P.S: I am using MS SQL Server 回答1: You can try doing an alter table. If it fails do this: Create a new column that's an integer: ALTER TABLE tableName ADD newCol int; Select the data from the old column into the new one: UPDATE tableName SET newCol = CAST(oldCol AS int) ; Drop the old column 回答2: It is possible only when you

SQL alter column datatype from nvarchar to int

China☆狼群 提交于 2020-06-11 16:50:31
问题 Can the datatype of a field be changed to int from nvarchar?? alter table employee alter column designation int is this valid?? If not can it be done in some other way?? P.S: I am using MS SQL Server 回答1: You can try doing an alter table. If it fails do this: Create a new column that's an integer: ALTER TABLE tableName ADD newCol int; Select the data from the old column into the new one: UPDATE tableName SET newCol = CAST(oldCol AS int) ; Drop the old column 回答2: It is possible only when you

Deal with awkwardness from adding timestamp column to mysql table

落爺英雄遲暮 提交于 2020-02-25 08:36:34
问题 I have a very large table that I want to add a timestamp column to. It is a table that gets a lot more updates than inserts. I am trying to figure out a way to do this without taking the table out of production for a significant amount of time and it has me in knots. I can do: alter table stuff add column mod_time timestamp; Well, I could do this and then the table is locked for 3-5 hours. Not a happy time for users. For adding a varchar column, for example, I could create a new table, add

MS Access - sql expression for allow null?

别来无恙 提交于 2020-02-05 15:51:57
问题 I use MS Access (2003) database. Once I create a column I set NOT NULL using sql statement: ALTER TABLE Table1 ALTER column myColumn INTEGER not null Is there a way to change it back to allow null values? I already tried: ALTER TABLE Table1 ALTER column myColumn INTEGER null but nothing... 回答1: You cant specify null in ALTER TABLE (although not null is allowed) See the below documentation and also this discussion on this toppic Syntax ALTER TABLE table {ADD {COLUMN field type[(size)] [NOT

How to change date format of datetime data type in SQL?

落爺英雄遲暮 提交于 2020-01-17 03:54:24
问题 My date format of "03-01-2017 10:24:48" is getting stored in SQL as "2017-03-01 10:24:48.000" where my 'dd-mm-yyyy' format is getting converted to 'yyyy-mm-dd' format. How can I change the date format of the column to my desired format? My table already contains data. 回答1: SQL Server doesn't store a DateTime in any string format - it's stored as an 8 byte numerical (binary) value. The various settings (language, date format) only influence how the DateTime is shown to you in SQL Server

Add column from development database table to production database table

亡梦爱人 提交于 2020-01-05 05:52:50
问题 I got an issue When some table on the development database has more columns added, and right now I should add the column in the production database. I try to add the column manually, by Add Column on Table Tree, but when I try to save, it show me a warning : here's the complete warning message : Saving Definition Changes to tables with large amounts of data could take a considerable amount of time. While changes are being saved, table data will not be accessible. is this safe? or is there

Alter Table too slow in postgres

孤人 提交于 2020-01-03 16:54:28
问题 I'm trying to add a new column ALTER TABLE "Cidade" ADD COLUMN "BoundBox" VARCHAR(255) to this table: "Cidade" "Id" integer not null constraint "Cidade_PK" primary key, "Nome" varchar(120), "EstadoId" integer not null constraint "Estado_Cidade_FK" references "Estado", "PontoCentralLatitude" numeric, "PontoCentralLongitude" numeric But the query never finish, I've already waited for 5 minutes and nothing happened. The table has only 5,000 records, and I can't wait too much time since it block

Postgres could not create unique index, key is duplicated

假装没事ソ 提交于 2020-01-03 11:45:26
问题 I'm trying to add a column to a table in my Postgres 9.3 database with this seemingly simple SQL: ALTER TABLE quizzes ADD COLUMN deleted BOOLEAN NOT NULL DEFAULT false; However, I'm getting the following error: ERROR: could not create unique index "quizzes_pkey" DETAIL: Key (id)=(10557462) is duplicated. Strangely enough, there are actually no rows with that id (which is the primary key, so it shouldn't have duplicates): SELECT id FROM quizzes WHERE id = 10557462; id ---- (0 rows) In fact, it

Postgres could not create unique index, key is duplicated

≡放荡痞女 提交于 2020-01-03 11:44:07
问题 I'm trying to add a column to a table in my Postgres 9.3 database with this seemingly simple SQL: ALTER TABLE quizzes ADD COLUMN deleted BOOLEAN NOT NULL DEFAULT false; However, I'm getting the following error: ERROR: could not create unique index "quizzes_pkey" DETAIL: Key (id)=(10557462) is duplicated. Strangely enough, there are actually no rows with that id (which is the primary key, so it shouldn't have duplicates): SELECT id FROM quizzes WHERE id = 10557462; id ---- (0 rows) In fact, it

Rename a column in mysql table without having to repeat its type definition

心已入冬 提交于 2020-01-01 08:18:17
问题 Is it possible to rename a column in MySQL without having to repeat its type definition? Please without having to hack into information_schema. 回答1: The ALTER TABLE syntax does not seem to offer such possibility: ALTER [ONLINE | OFFLINE] [IGNORE] TABLE tbl_name [alter_specification [, alter_specification] ...] [partition_options] ALTER [ONLINE | OFFLINE] [IGNORE] TABLE tbl_name partition_options alter_specification: table_options [...] | CHANGE [COLUMN] old_col_name new_col_name column