Questions tagged [alter-table]

SQL statement used to alter an existing table object.

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

ALTER TABLE statements not replicating in all tested scenarios - MariaDB

Summary Tech: mariadb 10.3 Issue: some attempts to ALTER TABLE to change engine is not replicating. Scenarios tested: command line PHP script running ALTER statements using PDO - did not replicate ...
1
vote
2answers
19 views

How to rename a column name which has been created by a math function in mysql? Using ALTER TABLE is giving ERROR: 1064 (42000)

INPUT: CREATE TABLE dist -> SELECT ST_DISTANCE(POINT(x1,y1),POINT(x2,y2)) -> FROM config; OUTPUT: +------------------------------------------+ | ST_DISTANCE(POINT(x1,y1) , POINT(x2,y2)) | +-----...
0
votes
1answer
16 views

Alter table generated text column to normal text column

If I have a table with a generated text column, how do I alter the column to remove the generation expression to get a normal, not-generated text type? Here's the schema: CREATE TABLE product_history (...
0
votes
0answers
36 views

Update table column without losing data when releasing a new version of software

I just linked my application with a database using sqlite. Everything worked fine. And I realeased a version of my app. So I find myself in need of changing a table attribute type. The sql statement I ...
0
votes
1answer
33 views

Alter a table column based on type

I am converting "timestamps without timezone" columns to "timestamps with timezone" on a number of tables. These are large tables and I am going to use batching and other ...
1
vote
1answer
58 views

Convert a postgres GENERATED column to a regular non-generated column (in place without DROP)

I'm using postgres 13.3, and I already have an existing table with a GENERATED column such as: CREATE TABLE test_table ( id uuid NOT NULL DEFAULT uuid_generate_v4(), the_column_to_alter bool ...
0
votes
2answers
49 views

Changing nvarchar (4000) to nvarchar(500)

I have a performance issue with nvarchar(4000). I want to alter the table as per the statement below: BEGIN declare @length as int SELECT @length = MAX(LEN([SourceId])) from [dbo].[table] if @...
0
votes
1answer
39 views

Make ALTER TABLE wait for lock without blocking anything else

Lots of PostgreSQL ALTER TABLE commands, like adding a new column with a default value, have clever optimisations in the latest versions of PostgreSQL that allow them to execute basically instantly, ...
2
votes
2answers
47 views

Convert postgres varchar[] to text[] without downtime

As I discovered in researching this question, converting a column from varchar(100)[] to text[] requires a table rewrite and rebuilding indexes. Is there a way to manage this conversion without the ...
3
votes
1answer
33 views

Postgres varchar(100)[] -> text[] column conversion

I need to change a column type from varchar(100)[] to text[]. The table has >100M rows and heavy write load, so I'd like to avoid taking an access exclusive lock and rewriting the index. I saw in ...
0
votes
3answers
41 views

Supplying root password to MySQL V8 sort of fails

On Ubuntu 20.04 I have installed MySQL V8.0.25. But I kind of fail to apply a (valid) root password. The apt-get process for installing mysql-server did not ask for a root password. And I cannot enter ...
0
votes
1answer
20 views

How to alter column to make it primary key when one already exists mysql8?

id | bigint unsigned | NO | PRI | NULL | auto_increment | | title | varchar(255) | NO | | NULL | | | category | varchar(255) | NO | | NULL |...
0
votes
2answers
41 views

Why is MySQL InnoDB table copied despite using ALGORITHM=INPLACE for ALTER TABLE

I run an ALTER STATEMENT on an InnoDB table on a MySQL server version 5.7 that: drop some foreign key constraints drop some indexes (non unique) add some columns (without index or foreign key ...
1
vote
1answer
39 views

Significant performance differences executing alter and grant statements between users with same permissions

I am experiencing significant performances differences between users with the same permissions when executing alter and grant statements. I have an automated build system that runs a series of SQL ...
1
vote
5answers
121 views

Why can't you add an Identity to an existing colum in SQL Server?

What is so special about an Identity column? I am pretty sure there is a valid reason, but I'm trying to get a better understanding of SQL. So what is so special about an Identity column that this can'...
1
vote
1answer
25 views

Suppressing SELECT output before \gexec?

This answer is great for when I needed to reown 150 tables, each with 40 tables, but displays the 6000 rows from SELECT before running the 6000 ALTER statements. Thus, as stated in the Subject, is ...
0
votes
1answer
34 views

Improving remake of primary key performance

I'm using a MySQL 5.7 hosted on AWS that has a table with about 500,000,000 rows and 124GB in size. I want to drop the existing primary key (id) and create a new composite primary key of 2 columns: ...
1
vote
1answer
159 views

Why do my RDS read IOPS drop after a certain period of time?

I am trying to add non-null constraints on several columns in a table with about 70,000,000 rows. Each statement is just ALTER TABLE table_name ALTER COLUMN column_name SET NOT NULL;, and each ...
0
votes
1answer
59 views

Change bucket count for Primary Key Nonclustered Hash on existing In-Memory table

I'm on SQL Server 2019 Enterprise edition. I have a table with this definition CREATE TABLE dbo.MyMemoryTable ( FirstId int NOT NULL, SecondId int NOT NULL, MyCount int NOT NULL, ...
0
votes
0answers
64 views

Snowflake: Creating a table with a column name which is ANSI reserved fails, but adding a column(alter table) same ANSI reserved column name succeeds

CREATE TABLE test_table (LOCALTIMESTAMP varchar(10)) This query fails with .invalid column definition name 'LOCALTIMESTAMP' (ANSI reserved) ALTER TABLE test_table ADD COLUMN LOCALTIMESTAMP varchar(...
1
vote
2answers
531 views

“Alter Table” modify multiple columns vs multiple Alter table single column in INNODB?

I am updating collations of my database tables and columns from utf8bin to utf8mb4_bin. Engine is INNODB with file per table enabled. I used a query to generate identify all utf8 columns from ...
0
votes
2answers
75 views

How to add generated column to db2 table?

I've got a table with the following: Columns: --- URL [nullable, e.g. "https://dba.stackexchange.com/"] APPFK [nullable, e.g. 654654] LINKTYPE ["Page", "Link", or "...
1
vote
1answer
18 views

Why am I getting an error if I am trying to modify data type? [closed]

I am facing an error when I passed the following syntax in MySQL: ALTER TABLE store MODIFY (DOB char(40)) ; I am attaching a screenshot too because then you can see that the column DOB is having all ...
5
votes
1answer
82 views

Why a dropped index is still there, and does it prevent a table from being altered?

I have a column (named RequestDate) which I need to change from NULL to NOT NULL, but there's a clustered index on that column, so I first need to drop that index. Originally, the index was created ...
0
votes
2answers
69 views

In mysql, how to add a primary key and a composite key to a table so that it forbids duplicate rows, when there are null values within the columns?

In the following table (8 mi rows), every column has Null values. However, there can never be two identical rows (there will be always at least one column with a different value for each row). How can ...
0
votes
1answer
89 views

How do you change the storage parameters of a already made table (sql developer)?

Summarize the problem I have been given 6 tables that have all been created already and I was told to change the storage parameters of those tables. the issue I run into is that I can only change ...
0
votes
1answer
41 views

alter table alter column causes huge log and data file growth

I have a table with 2.6B rows in it and I need to change a column from Char(1) to Varchar(64). the table is over 300GB with a few indexes. The column in nullable, so the transaction i'm running is: ...
1
vote
2answers
41 views

Promote MySQL Table Partition to Table

My Google Searching skills were not enough to find a solution to this. If possible, how can I promote a partition on a table to a table on its own? Let's assume I have part0, part1, and part2. Is ...
0
votes
1answer
39 views

SQL Server :: how to move country code column to another table?

I have 2 tables: tbl_Countries: 250 values, with columns like CountryName (Afghanistan), TwoCharCountryCode (AF), ThreeCharCountryCode (AFG). Like this: CountryName TwoCharCountryCode ...
0
votes
1answer
50 views

Why is ALTER faster than UPDATE (for full table rewrites)?

Let's create a garbage table.. CREATE TABLE foo AS SELECT x::text FROM generate_series(1,20e6) AS t(x); Time: 14077.654 ms (00:14.078) Now, let's look at boring UPDATE, UPDATE foo SET x = 'foo'; ...
0
votes
1answer
24 views

How to insert '1001-01-01 00:00:00' into MariaDB when altering a table?

I created a table in HeidiSQL: CREATE TABLE `publish_dt` ( `ID` BIGINT(20) NOT NULL AUTO_INCREMENT, `TS` DATETIME NULL DEFAULT NULL, `Text` VARCHAR(50) NOT NULL COLLATE 'utf8mb4_unicode_ci'...
0
votes
1answer
337 views

Alter column fails due to “hidden” statistic

I'm trying to change a column data type from datetime2 to datetimeoffset. I have db owner permissions. Whenever I run the query: alter table dbo.<my-table> alter column [TimeStamp] ...
1
vote
1answer
399 views

MySQL Store Procedure - Setting AUTO_INCREMENT value

I am in trouble coding a store procedure as shown below CREATE DEFINER=`dbcomexuser`@`%` PROCEDURE `clearance_imp`(IN CAPIfilename VARCHAR(12)) BEGIN DECLARE `_rollback` BOOL DEFAULT 0; DECLARE ...
0
votes
1answer
532 views

Why is ADD CONSTRAINT … NOT VALID taking a long time?

I added NOT NULL constraints to some columns like this, expecting the command to be very fast because of NOT VALID. However, it took about 60-100 seconds, and seemed to lock the table for the whole ...
0
votes
1answer
32 views

Specific format/formula when changing column datatype [duplicate]

Can one modify a column's datatype using a very specific conversion format? For example, when converting from datetime to varchar I'd like to use the yyyy-MM-dd hh:mm:ss format, not the system ...
0
votes
2answers
193 views

MySQL: change column type using expression

In a MySQL database, I need to convert some UUID columns (BINARY(16)) into VARCHAR. I want to convert them in the canonical form, not as bytes. For clarity, in lowercase and with hyphens, and not in ...
5
votes
2answers
827 views

How can I set a column to NOT NULL without locking the table during a table scan?

(former question was: Will Postgres use a multi-column index when setting multiple colums not null?) Typically, when I set a column not null, if it doesn't have an index then I add it first, so that ...
1
vote
3answers
248 views

How to calculate end_date from start_date and duration in SQL Server Query

I have a table with 4 fields .Start-date, Duration, End_date, Actual_date. I am providing the start_date and duration as the input to calculate end-date. While calculating the end_date the ...
0
votes
0answers
26 views

Check constraint on grouped conditions

Take the following table as an example: GroupID AlphaID BetaID 1 0 1 1 1 1 1 2 2 2 0 1 2 1 2 ...
0
votes
1answer
92 views

How to fix conversion error from InnoDB to MyISAM?

How can I fix conversion error from InnoDB to MyISAM for these tables? MariaDB [db_name]> ALTER TABLE wp_posts ENGINE = MyISAM; ERROR 1071 (42000): Specified key was too long; max key length is ...
0
votes
1answer
23 views

Atler Table Alter Column Set Default FALSE: Why my alter table took 10 minutes to finish?

I have run the following command and it took about 10 minutes to finish: ALTER TABLE "bookings" ALTER COLUMN "local_direct_booking" SET DEFAULT FALSE for a table bookings which had 111.834 rows (...
0
votes
1answer
160 views

MySql Error #1054 when adding new column to table using prepared statement

I'm trying to add a new column named lot to a table, but I'm getting error #1054 - Unknown column 'lot' in 'field list'. What could be the problem? Here's the query: SET @lot = (SELECT lot_no_start ...
0
votes
0answers
24 views

Adding a column and new foreign key constraint in one line

Let's say we have a table called Salesman with the folling properties Create Table SalesMan( EmplyeeId int Primary Key, Name varchar(20) Not Null, LastName Varchar(20) Not Null, Email Varchar(...
0
votes
0answers
34 views

Alter Table operations blocks replication in MySQL

We are using Amazon Web Service's MySQL 5.7.26 with 4 read-only replicas. After some Alter Table operations we have found that the replication stops working. The symtoms are great replica lag that is ...
1
vote
1answer
57 views

Does “alter table … set data type” functionally differ from “alter table … type”?

The docs show [SET DATA] TYPE which implies the SET DATA part is optional, but the 9.1 release notes also imply that SET DATA TYPE may be different: Allow ALTER TABLE ... SET DATA TYPE to avoid ...
2
votes
1answer
290 views

ALTER fixed-length COLUMN on compressed table

I wonder if compression of a table actually changes ALTER TABLE rules. I found no information on this topic. Let's consider a simple example. I'll create a table and alter one of the columns from INT ...
0
votes
1answer
111 views

Alter on huge table consumes all disk space

I'm running MySQL 8 on Ubuntu 19. I have a table that is 543G and I have to add a new column and index. I've started with the new column: alter table hugeTable add column newCol tinyint(1) after ...
0
votes
0answers
46 views

ALTER TABLE query to convert table to utf8mb4_bin takes many hours - how to optimise this?

I have a table which has approx 15 million rows - I won't add the schema here but it has 96 columns (far too many in my opinion). The current table collation is latin1_swedish_ci but for full emoji ...
4
votes
1answer
317 views

Prevent drop column with index on it in PostgreSQL

In PostgreSQL when you drop column in a table, all indexes and constraints which use this column will be also dropped silently. If you overlook such situation, you can get serious problems in ...
0
votes
0answers
331 views

Dynamic script to alter a column type having an index

I am writing a script to update the datatype of a column in SQL Server on a list of tables, if the existing column are not yet of the desired type. The column should be converted from a VARCHAR to a ...

1
2 3 4 5
7