Questions tagged [alter-column]

Alter column is a part of sql's Alter table statement used to change an existing column in a table.

Alter column can be used to set a default value, changing the column's data type, or changing the column's maximum length.

Alter column is supported in Microsoft Access and in Sql Server. To modify columns properties in Oracle, for example, you will need to use Modify column instead.

Alter column related tags

62 questions
0
votes
1 answer

Why can't I convert a column from one enum to another?

Given this setup create type myenum_one as enum('foo', 'bar', 'baz'); create table mytable ( myvalue myenum_one ); alter table mytable add constraint mycheckconstraint check (myvalue != 'bar'); insert into mytable values ('foo'); create type…
Lorentz Lasson
  • 885
  • 8
  • 26
0
votes
1 answer

Unable to change my time column from string to time in Bigquery

I have a column that I made as HH:MM:SS in Excel, but when I moved it to Bigquery, it kept the format but changed to string. I need to change it back so that I can find averages. At first I just tried altering the table: ALTER TABLE…
oastephs
  • 9
  • 3
0
votes
1 answer

Altering Column Type in SQL (PGadmin) not working

I am new to DB design and have created my tables in Postgres. However, I need to change the datatype of one of my tables from date to integer'. However, when I add the code in to do this, I get the following error: ERROR: cannot cast type date to…
P.D.R
  • 3
  • 2
0
votes
1 answer

SQL Server - Alter column length causes collateral damage?

Besides the obvious possible data loss, when altering the size from varchar(MAX) to varchar(255), are there any side effects? Like: table-lock? index corruption? Automatic re-indexing? This is the kind of activity that can be conducted at any time…
Leonardo
  • 10,737
  • 10
  • 62
  • 155
0
votes
1 answer

Alter column type deleting those that can't be converted

I need to change the type of a column from varchar(255) to uuid. I am using: ALTER TABLE table_name ALTER COLUMN col TYPE UUID USING col::UUID; But if there is some value in that column, which is not in uuid format, I will get this error: SQL…
Faizan Khalid
  • 125
  • 2
  • 9
0
votes
2 answers

Why is the column not altering when I try to convert it to UUID?

I have a primary key column in my SQL table in PostgreSQL named "id". It is a "bigseries" column. I want to convert the column to a "UUID" column. It entered the below command in the terminal: alter table people alter column id uuid; and alter…
user16767975
0
votes
1 answer

Altering data types of all columns in a table (PostgreSQL 13)

I have a table import.hugo (import is schema) and I need to change all columns data type from text to numeric. The table already has data, so to alter column (for example) y I use this: ALTER TABLE import.hugo ALTER COLUMN y TYPE numeric USING…
0
votes
1 answer

Missing Expression when Alter Default on NULL 1

I have column in table book... named as status... i want to set default 1... but, i tried DEFAULT 1, ALTER TABLE book MODIFY status DEFAULT 1 and i insert new record... the record status is null i tried to use Default on null 1 ALTER TABLE book…
via
  • 40
  • 6
0
votes
1 answer

How can I change the precision of a datetime2 for a system-versioned table (temporal table) in SQL Server?

I have 62 tables that were set up as system-versioned/temporal tables except the start and end time columns were set up as datetime2(0) as shown below. SysStartTime [datetime2](0) GENERATED ALWAYS AS ROW START NOT NULL, SysEndTime [datetime2](0)…
bm11
  • 43
  • 8
0
votes
2 answers

Error in changing column length in Postgres

I am trying to change the column size from 100 to 150 varchar data type using following query: alter table data_warehouse.tbl_abc alter column first_nm varchar(150) null; Getting the following error: SQL Error [42601]: ERROR: syntax error at or…
0
votes
2 answers

How to set NOT NULL to a column present in all the tables of my database at once?

I'm working with PostgreSQL. I have to set the NOT NULL property on a column that exists in all the tables of my database. I know how to set in one table, using: ALTER TABLE table_name ALTER COLUMN column_name SET NOT NULL; But I have about 400…
La Rosalia
  • 18
  • 4
0
votes
1 answer

Alter Column TYPE USING - cannot change from varchar to numeric

I would be eternaly grateful if somebody could help me a bit. I am totally new to Postrgresql 10 I had a large file millions of lines 73 columns, I could not imported so I set all the columns to varchar. Now I need to manipulate the data I cannot…
Alex
  • 35
  • 2
  • 4
0
votes
0 answers

Alterar una columna, para cambiar "nulo" a "no nulo", cuando no se conoce el tipo de datos

I need to allow nulls in a column, but I don't know its data type. In oracle its possible to do this: alter table MyTable modify MyField null; the SQL server homologous statement requires the data type (in this example INT): alter table MyTable…
GatoSoft
  • 106
  • 1
  • 3
0
votes
1 answer

EF migration can't Alter(change) Datetime(DataType) column to long(bigint)

I use EF code first approach and altering database by package manager console Trying to change column invoiceno Datetime to long Add-migration "message" Update-Database command returns error Implicit conversion from data type datetime to bigint is…
Baganaakh
  • 67
  • 1
  • 3
  • 17
0
votes
0 answers

How to write a script to add column to multiple views using single script?

I am looking a script which allows me to add single column to multiple views. I am using SQL Server. For Ex. I have view1, view2, view3 with column1, column2. I need to add column3 in all the views How can I do that ? Any help is highly appreciated.