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).

1118 questions
-1
votes
1 answer

Alter column length in SQL

ALTER TABLE tableName MODIFY COLUMN columnName VARCHAR (256); Error : Incorrect syntax near 'VARCHAR'
-1
votes
2 answers

Add calculated column to table ssms (sql query)

Im trying to add and save a new calculated column to the table energy, using the following sql query: ALTER TABLE energy ADD energie_active_1 float SELECT *, energie_active - LAG(energie_active, 1, energie_active) …
-1
votes
1 answer

Set auto_increment for a primary key already created

I created two tables in a database on MariaDB: CasaProduzione and Produzione. create table CasaProduzione(nome varchar(80) primary key); alter table CasaProduzione add column id tinyint; alter table CasaProduzione drop primary key; alter table…
keiichi
  • 113
  • 1
  • 1
  • 10
-1
votes
1 answer

Postgresql issue: help needed

ALTER TABLE populated_places ALTER COLUMN geom TYPE geography(Point, 4326) USING ST_Transform(geom, 4326) says: ERROR: function st_transform(geography, integer) does not exist LINE 4: geom TYPE geography(Point, 4326) USING ST_Transform(geom,…
-1
votes
1 answer

Keep getting incorrect syntax near keyword CONSTRAINT in ALTER TABLE when trying to create foreign keys for a table?

I am currently I am working in sql server and have the following code. I am trying to create two foreign keys under the 'ASSIGNMENT' table, as well as create a primary key for the 'ASSIGNMENT' table. However, I keep running into problems when trying…
user18146581
-1
votes
1 answer

Is it safe to add IDENTITY PK Column to existing SQL SERVER table?

After rebuilding all of the tables in one of my SQL SERVER databases, into a new database, I failed to set the 'ID' column to IDENTITY and PRIMARY KEY for many of the tables. Most of them have data. I discovered this T-SQL, and have successfully…
Jeff King
  • 1
  • 3
-1
votes
2 answers

MySQL Error 1366 when trying to change column data type to INT

I can't figure out why I can't change a column's data type from TEXT to INT. Here is the script I'm using. ALTER TABLE covidworlddata.coviddeaths ALTER COLUMN total_deaths INT; Error 1366: Incorrect integer value: '' for column 'total_deaths' at…
Adam
  • 1
  • 2
-1
votes
3 answers

How to remove unique constraint in MySQL?

I was searching online about how to remove unique constraint in MySQL in the Internet and I found a lot of solutions. DROP INDEX index_name ON table_name; ALTER TABLE table_name DROP INDEX index_name; ALTER TABLE table_name DROP CONSTRAINT…
-1
votes
2 answers

What does the FOR keyword do in this SQL Server ALTER TABLE clause?

I'm not sure what FOR is doing in this SQL Server snippet. ALTER TABLE [dbo].[TableName] ADD DEFAULT (NEXT VALUE FOR [dbo].[TableName_Seq]) FOR [TableName_Key] When I try to google for FOR clause the only meaningful result I got was this, but…
Jimmy Vo
  • 124
  • 2
  • 11
-1
votes
1 answer

Removing a constraint in T-SQL by alter table command - problem

I have got the following code in t-SQL: alter table Persons drop primary key; And the message: Msg 156, Level 15, State 1, Line 10 Incorrect syntax near the keyword 'primary'. I have checked different combinations of syntax and none have…
-1
votes
2 answers

Add new column to all tables in database

I'm trying to figure out if there's a quick way or single query to add a new column to all tables in database. Right now I'm doing this for each table ALTER TABLE [dbo].[%TABLE_NAME%] ADD %COLUMN_NAME% DATATYPE NOT NULL DEFAULT %VALUE%; Is there a…
Anthony R
  • 89
  • 1
  • 10
-1
votes
1 answer

Adding column to table based on whether another column = a specific string

I want to add a column called "Sweep" that contains bools based on whether the "Result" was a sweep or not. So I want the value in the "Sweep" column to be True if the "Result" is '4-0' or '0-4' and False if it isn't. This is a part of the table: I…
RKS2
  • 25
  • 11
-1
votes
1 answer

SQL query with ALTER TABLE print error #1064 in query execution

I've built an SQL query in Aruba MySQL database using the alter table Statement to generate a new column with comma-separated values. I'm trying to automate the concatenate function every time a new record is submitted into the database table. After…
-1
votes
1 answer

Simple SQL question: where is the syntax error?

sqlite> .schema autor CREATE TABLE autor (ID INTEGER PRIMARY KEY, NOME TEXT, CIDADE TEXT, ESTADO TEXT, TELEFONE TEXT, idade number); sqlite> alter table autor drop idade; Error: near "drop": syntax error (Also tried to use DROP COLUMN instead of…
-1
votes
2 answers

Varchar to nvarchar without changing length

I have this table that stores an id for each row in sub_id column of type varchar(255), sql server. Other columns store unicode thus those are nvarchar. Now I have this need to update sub_id to nvarchar for SOME reason. I ran following command: …
pyroCoder
  • 160
  • 2
  • 14