Questions tagged [alter-table]

The "ALTER TABLE" is a SQL statement that allows you to make schema changes to a database table (i.e. add, drop or alter columns from an existing table).

Filter by
Sorted by
Tagged with
0 votes
1 answer
22 views

Does MySql ALTER TABLE command affects rows?

I'm using query ALTER TABLE `DEPLOYMENT` CHANGE COLUMN `ID_` `ID_` VARCHAR(100) NOT NULL  -> 72 row(s) affected Records: 72 Duplicates: 0 Warnings: 0  0.281 sec But 2nd time while executing same ...
Blackarch's user avatar
1 vote
1 answer
64 views

Alter column type from text[] to jsonb[]

I have a text[] column which consists of elements of stringified JSON, and I want to convert it to jsonb[]. Here is my table reduced to the relevant text[] column: CREATE TABLE certificate ( ... ...
Ahmet yazıcı's user avatar
0 votes
1 answer
82 views

How to change the description of a field nested in a struct via the DDL in BigQuery?

Let's say I have the following table: CREATE OR REPLACE TABLE tmp.table_description_test AS ( SELECT 1 AS a, STRUCT(2 AS c, 3 AS d) AS b ) Adding a description for a or b is easy: ALTER ...
Tobias Hermann's user avatar
1 vote
1 answer
67 views

ALTER TABLE WITH SELECT

I need to find all uppercase column names in our databases and alter them to lowercase. However, I'm having troubles making this work. Any help is appreciated ALTER TABLE (SELECT quote_ident(c....
Travis's user avatar
  • 43
1 vote
2 answers
46 views

Altering column data type

How can I alter a column of number to a list of numbers. In myTable, m_no is an integer. Now I wish to change m_no column to a list of integers without loosing the currently stored values. CREATE ...
Grandmarkkk's user avatar
1 vote
0 answers
106 views

ERROR: ALTER TABLE APPEND cannot run inside a multiple commands statement

I'm trying to iteratively pull data from MySQL and build a table in RedShift. But getting this error on APPEND db = <some_db> table_name = 'test' table_name_full = f'{db}.{table_name}' cols = ['...
Raksha's user avatar
  • 1,619
0 votes
1 answer
50 views

Unanticipated Index Creation in MSSQL and its Impact on Column Alteration - INDEX_VV_<3to4DigitNumber>_<3to4DigitNumber>

SQL Version - 12.00.6118(SQL Server 2014) In MSSQL, indexes are created in a few tables and certain columns apart from the ones defined in the schema with the index name format 'INDEX_VV_<...
rootcause000's user avatar
-1 votes
2 answers
58 views

I want to replace fields with STRING with correct data type FLOAT64 in BigQuery. How do I do it?

I am new to learning Data Analysis. I have a field in my BigQuery dataset named Unemployment_rate that should be FLOAT64. However, some fields that should be 0 are represented as 'NaN', which is ...
Sylvia Ikeji's user avatar
0 votes
3 answers
82 views

Need to Alter data type in a column common to all tables in a schema

I need to alter the Data Type of a named column (let's call them 'photo') across all the tables in a schema. For example: I have 300 tables with identical structure (except the data in each row of ...
fulgore's user avatar
  • 11
0 votes
2 answers
56 views

change / rename column if exists mariadb

I couldn't remane my column if it existed, this is what i tried (i'm adding the different lines tested in same ALTER my_table to summarize) : ALTER TABLE my_table RENAME IF EXISTS column_name TO ...
Brice B's user avatar
  • 123
3 votes
1 answer
640 views

Oracle ALTER TABLE MOVE INCLUDING ROWS not working properly

I'm trying to use ALTER TABLE MOVE...INCLUDING ROWS as a faster alternative to DELETE, but it's not working as expected when: An index exists, and The filtering condition results in an empty table ...
Tianxiang Xiong's user avatar
0 votes
0 answers
414 views

ALTER TABLE ADD COLUMN AFTER does not add my column after specified column Delta table

I want to add a column to my delta table via Databricks SQL. Following the syntax on the Microsoft site https://learn.microsoft.com/en-us/azure/databricks/delta/update-schema and Databricks site https:...
CClvu's user avatar
  • 1
0 votes
0 answers
139 views

ALTER TABLE on PRIMARY KEY without downtime or lock table

I'm trying to change the type on the PRIMARY KEY from INT to UNSIGNED INT on MySQL server because I'm nearing the end of the INT range. I tried to make a query ALTER TABLE table_name CHANGE id id INT ...
Adabler's user avatar
  • 34
0 votes
1 answer
61 views

Getting an error with my ALTER TABLE syntax

Can someone check this syntax for me? I'm getting an error... I need to change TIME to BEGIN_TIME and then add a column for END_TIME. Thanks in advance! ALTER TABLE LABINFO_WARDL.DIM_TIMEPERIOD ...
taipei2sc's user avatar
0 votes
1 answer
48 views

loose keys after alter table set schema

ran into a problem on PostgreSQL 12.5 ALTER TABLE old_shcema.my_table SET new_schema first - everything is OK, everything is transferred except triggers, but if you try back ALTER TABLE new_schema....
Masta's user avatar
  • 81
0 votes
1 answer
245 views

Cannot drop column with ALTER TABLE [duplicate]

I cannot drop a column with ALTER TABLE. I create a table within SQLite: sqlite> create table example ( "field" text not null ); sqlite> .schema CREATE TABLE example ( "field"...
Henrique Bucher's user avatar
0 votes
1 answer
258 views

DB2 ADD a new COLUMN to a table with DEFAULT value from an EXPRESSION using existing data in another column

ALTER TABLE my_table ADD COLUMN new_column_name data_type DEFAULT expression; Is it possible to use an existing column data as default value for a new column in DB2? ALTER TABLE employees ADD COLUMN ...
G 1's user avatar
  • 643
2 votes
1 answer
57 views

Adding autogenerated column that computes frequencies

I would like to create a generated column in my SQL table products who's value is automatically calculated by COUNTING the frequency of values in another column. Please see example below, ...
BoggyB's user avatar
  • 23
0 votes
1 answer
51 views

Can a column be restricted to taking one or another foreign key as an entry?

I have been attempting to constrain a column to accept an entry which can only be foreign key A entry OR foreign key B entry but I am not sure if this is possible? For context I am creating a helpdesk ...
sdaw145's user avatar
  • 33
0 votes
0 answers
46 views

ALTER TABLE Issue in Aurora MYSQL table

I was trying to execute the below SQLs in Aurora MYSQL DB v5.7.12 but getting getting error like this. I searched all over internet this is exact syntax shown everywhere, not sure what I am missing. ...
sanju's user avatar
  • 31
0 votes
1 answer
13 views

How to pass multiple columns to replaceColumn! at once?

I want to change the data type of specific columns with replaceColumn!. But I can only pass one column at a time to the function. How to change the data types of multiple columns with just one command?...
zhihengqu's user avatar
  • 421
0 votes
0 answers
72 views

How can I grant alter table permission to a user for specific schemas in AWS Redshift?

I'm trying to make a user able to have alter table permission to all tables in a certain schema but not in other schemas in AWS Reshift. So far, following the guidance here Grant alter table on an ...
Abednego Santoso's user avatar
1 vote
3 answers
59 views

Create a concatenated column to an existing table

I added the column using the alter table function, but I am now trying to use the 'update' and 'set' syntax to successfully update the table and translate the data over in the desired format I'm ...
Jake S's user avatar
  • 11
0 votes
1 answer
163 views

Will a column be dropped if deleted it from information_schema.columns?

I use Postgres 14. I know about ALTER TABLE DROP COLUMN. But this option doesn't really work in my case. Are these two queries equal: ALTER TABLE <some_table_1> DROP COLUMN IF EXISTS <...
Prosto_Oleg's user avatar
0 votes
0 answers
47 views

SQL-Create a new column based off existing column from results list

I have a SQL Query in Google BigQuery which collects all the information I need properly. However My 5th column, 'NewcustomerOverride" yields numerical answers that don't mean much at first ...
Bryan-Lee Edwards's user avatar
2 votes
1 answer
98 views

Alter command is failing due to unique key constraints of another existing field in mysql

So I am running a migration command ALTER TABLE wallet_transactions ADD COLUMN entity_type varchar(100) NULL, ADD COLUMN entity_value varchar(100) NULL; on a table which has more than 34 million rows,...
Yooooooo_G's user avatar
0 votes
1 answer
171 views

PostgreSQL migration from TEXT to INTEGER with existing data which can be null

I'm trying to perform alter table column change from TEXT to INTEGER in PostgreSQL database like below: ALTER TABLE analyzer_parser_event ALTER COLUMN error_id TYPE INTEGER USING (error_id::integer); ...
Krzysztof Michalski's user avatar
-2 votes
1 answer
143 views

Add a mandatory column of dates to an existing table [duplicate]

I want to add a new column called 'start_date' to a table called 'PROJECT', and I want this column to be mandatory. I have tried this: ALTER TABLE PROJECT ADD start_date date NOT NULL; This returns ...
alasdair hando's user avatar
0 votes
1 answer
45 views

BigQuery. Adding a query as a column to a table

SELECT TIMESTAMP_DIFF(ended_at, started_at, MINUTE) AS trip_duration FROM coursera-practice-356200.Cyclistic_data.cycledata_202202-202301 This is the query I am starting from. I am new to SQL and I ...
YellingYeti's user avatar
0 votes
1 answer
28 views

Adding column with defaults without retrofitting value

If I have a table like this: CREATE TABLE customers ( id INT PRIMARY KEY, address VARCHAR(255) ); INSERT INTO customers(id,address) VALUES (1,'Here'),(2,NULL); I know I can add an additional ...
Manngo's user avatar
  • 14.6k
1 vote
1 answer
481 views

How do I use ALTER TABLE to ADD CONSTRAINT as an INDEX

I would like to use the ALTER TABLE command to ADD CONSTRAINT. I do this often with no issues but in this case I need to add it as an INDEX as well. From the Microsoft website it shows the following.....
Arvo Bowen's user avatar
  • 4,594
1 vote
2 answers
448 views

PostgreSQL: error with ALTER TABLE ... ADD CONSTRAINT UNIQUE

I am trying to add a column and a new constraint to a simple table in Postgres. It's balking on the keyword UNIQUE. I've gone back and forth between my sliver of code and the documentation for ALTER ...
Randall's user avatar
  • 2,877
0 votes
1 answer
15 views

How to return a new table after modifying the columns, instead of changing the original table?

How to return a new table without changing the original one when I use tmpTB.replaceColumn!(args)? Is there a parameter like inplace=False in pandas?
YaN's user avatar
  • 417
1 vote
0 answers
59 views

Can I add a new column in a sql table which is already partitioned.(SQL Server )

I have a table which is partitioned on x column, but now I want to add new column(y) which is not related to partitioned column. So I used Alter command to add new column(y), but suddenly this y ...
Vasundara's user avatar
0 votes
1 answer
157 views

MariaDB changing column type locks the table?

I was looking for better documentation, of what happens behind the scene when you change column definition. i.e. I want to change a column type from tinyint to int, and my table has 4+ million records....
Mali C.'s user avatar
  • 11
0 votes
0 answers
36 views

Giving Optimizer Hint on DDL Queries

How to give optimizer hints on DDL query ? I have a use case to set lock_wait_timeout in an alter query. I do prefer to give it for that statement alone. Is it possible to give optimizer hint in the ...
INDIAN DECODER's user avatar
0 votes
0 answers
23 views

Im not sure if my code works and i don't know how to test it

Ignore the names of everything, they're in Croatian. Im not sure if the logic of my alter tables and constraints are correct and if the syntax is properly written. If someone could check I would be ...
Noa Mazur's user avatar
0 votes
1 answer
69 views

CASE expression to help altering data type text to boolean

I have a column called still_available with the values of 'Removed' and 'Still_available'. The original table looks like this: Since there are only two values I want to cast it to boolean e.g '...
Swinging Treebranch's user avatar
0 votes
0 answers
43 views

EF Core and ALTER TABLE statement conflicted with the FOREIGN KEY CONSTRAINT

I have the following Dtos public class OrganizationDto { public OrganizationDto() { } public OrganizationDto(string name, string subscriptionPlan) { Name = name; ...
mrhusky's user avatar
  • 31
0 votes
1 answer
237 views

Drop column in Impala

I want to drop the whole column 'index' (column name and values) in Impala: index case_id customer_id 1 A xxx56 I used this code: ALTER TABLE DBName.Tablename DROP COLUMN index; The result is like ...
Sang Nguyen's user avatar
0 votes
1 answer
59 views

SQL Server How to add trigger to create same column in another table

I'm trying to figure out how to write a trigger that will add a newly created column to another table. Situation: I have dbo.tableA and dbo.tableA_Archive tables. When I add a column to dbo.TableA ...
Semperfi89's user avatar
0 votes
1 answer
48 views

Automatically change the name of column everywhere with the renaming the name of column

I need to change my column name in mysql and I want to automatically update all triggers, procedures, functions where that name is used to new name. How can I do this? I tried this syntax but it doesn'...
Nika's user avatar
  • 369
0 votes
1 answer
120 views

Alter Hive partition column name NOT changed in HDFS

When alter the partition column name of the partition table(named partitioned_table), the corresponding directory in the HDFS does not change. However, the deletion and movement of partitions can be ...
DylanGong's user avatar
0 votes
0 answers
184 views

Creating Table Relation with DrawSQL, exporting in PhpMyAdmin

When I create my tables with relationships in DrawSQL, I have a problem when I import my database in PhpMyAdmin, the alter table (relation) doesn't work. It seems that the relations between the tables ...
iamhmh's user avatar
  • 1
0 votes
1 answer
112 views

Change PRIMARY KEY CONSTRAINT in PostgreSql using Play Framework Evolutions

I need to change a PRIMARY KEY CONSTRAINT in PostgreSql from a single to a composite key, using Scala's Play Framework Evolutions. This Change Primary Key post gives me a good head start, so I will ...
Ricardo's user avatar
  • 3,856
0 votes
0 answers
29 views

Sql insertion of column with calculated value. Error subqueries are not allowed in this context

I'm trying to run this query, but I'm receiving this error: Error subqueries are not allowed in this context. Only scalar expressions are allowed. Alter Table dbo.factures_wtd ADD [WTD] AS ( ...
Mahmoud Bouhorma's user avatar
2 votes
1 answer
82 views

Key column X doesn't exist in table while trying to drop X from table

I need some help. I'm trying to run some migrations scripts on a NEW docker instance (the old one and local works fine). Mariadb, Innodb engine. I have a migrations like this: ALTER TABLE userinfo ...
Pikappa's user avatar
  • 282
-1 votes
1 answer
94 views

How to reindex primary key table in OLEDB with VB.NET

I created my own index primary key with the .NET progran VB.NET. So how can my solution re-index the primary key and then load the database Thanks Private Sub Form1_Load(ByVal sender As Object, ...
roy's user avatar
  • 693
0 votes
1 answer
27 views

Is there an update to set commas to existing integers/decimals used as currencies in a table?

Data already exists, but since it refers to large amounts, it's not so readable without commas. I've read this is the function: (https://i.stack.imgur.com/LVoEC.png) but how do I make a sentence to ...
Ame's user avatar
  • 1
0 votes
1 answer
369 views

MySQL throwing syntax error while trying to alter a table

I have been trying to alter a table to include a date column with default value of CURDATE() but MySQL is constantly throwing syntax error. Now, I have checked syntax for altering a table from several ...
Siddharth Das's user avatar

1
2 3 4 5
23