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).
Questions tagged [alter-table]
1118 questions
-1
votes
2 answers
Add a first day column to table with expression
I am using Below code to add a first day of the month column to the table with an expression to update automatically. But it's throwing a syntax error. someone pls do help.
ALTER TABLE `abc`.`t1`
ADD COLUMN `First_Day` DATE NULL DEFAULT select…
-1
votes
1 answer
Custom SQL with ALTER TABLE
In Tableau, I'm trying to add a column through Alter Table in a custom SQL
It looks like this:
ALTER TABLE (SELECT [W$].[W], [W$].[SDate], [W$].[EDate], [Date E$].[Date]
FROM [W$],[Date E$]
WHERE [Date E$].[Date]
BETWEEN [W$].[SDate] AND…

Jummi
- 123
- 1
- 13
-1
votes
1 answer
How To Delete One More Primary Keys in SQL?
i trying delete all primary keys one table on SQL.
If i had one primary key, i can deleted this code line:
ALTER TABLE dbo.TblName DROP CONSTRAINT PK_TblName;
But, if i have one more primary keys, i take this error:
Msg 3728, Level 16, State 1,…
user9914768
-1
votes
2 answers
SQL errors when inserting data
I'm trying to create a SQL Server database right now but I'm getting errors that I can't seem to solve. I'm a student trying to better myself by working on assignments I find on the internet and this one has me stumped. Below is the errors I get…

NoLuckCollector
- 65
- 8
-1
votes
1 answer
Add column into Table through variable using SQL Server
I have check unique value in the column VariantSKU using this sql code
alter Proc spIsUnique
@columnname nvarchar(max),
@tablename nvarchar(max)
As
Begin
EXEC ('select '+@columnname+',
IIf (count(*)>1,''False'',''True'') as Total
from…

Awesome
- 560
- 2
- 7
- 18
-1
votes
2 answers
Can I change the data type of my primary key on a temporal table?
In SQL Server 2016 Express, I initially made a table with a primary key that used the int datatype. Now, further into the project, I've realized that I need this column to be a string datatype, but when I try this:
alter table ExpAwbs
drop…

Josh Eblin
- 95
- 1
- 9
-1
votes
2 answers
Syntax error Change in database - SQL Server 2012
I'm trying to run this change in SQL Server 2012 on the basis of Mantis and is presenting syntax error, but can not understand where I've tried to use even the SET command before the DEFAULT and the error is the same:
The default value of the…

Paulo Roberto
- 1,498
- 5
- 19
- 42
-1
votes
1 answer
Modify column length in MySql
I'm issuing the following command:
ALTER TABLE `table_name` MODIFY `column_name` VARCHAR(1022)
At the moment it's VARCHAR(1024), however I'm getting this error:
Error Code: 1265 Data truncated for column mysql
I guess it's because some rows are…

Rafael
- 1,099
- 5
- 23
- 47
-1
votes
2 answers
The multi-part identifier could not be bound when altering a table
I'm running into an error when altering a table in an SQL server, the query is simply this:
ALTER TABLE t_OrderDetail DROP COLUMN [TotalCost];
GO
ALTER TABLE t_OrderDetail ADD TotalCost
AS (((t_OrderDetail.[ItemQuant] * t_Item.[ItemCost]) * 17.5) /…

RyanHx
- 411
- 3
- 10
-1
votes
1 answer
How to modify a column if it happens to be a MySQL type?
I have a table called sidebar_items and it has a Type column, which is of type enum('image', 'html'). I would like to change this column to be of type enum('image', 'html', 'structure'). I have tried this:
alter table sidebar_items modify Type Type…

Lajos Arpad
- 64,414
- 37
- 100
- 175
-1
votes
1 answer
Mysql - alter table
I want to add new column in my table with date, but I want to give value 000-00-00 in timestamp format to existing record and current_timestamp to new records. Is it possible? how?

Mateusz Chudy
- 45
- 1
- 8
-1
votes
3 answers
Alter table for add columns and constraints
Hello i have this but it show error
ERROR 1064 (42000) at line 61: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(
ADD COLUMN `CIUDAD_ID` int(11) NOT NULL…

Luis K Suarez
- 19
- 7
-1
votes
1 answer
Error when link 2 table in sql server
I am trying to link 2 table in sql server let's assume one of them called customer and the other is product.
customer has custID as primary key and i want to link it with custID in product table as foreign key, and its give me this error:
The ALTER…

Besh Mohammed
- 1
- 4
-1
votes
1 answer
ORACLE - Enable Unique constraint issue (same constraint name, multiple schemas)
I'm having an issue trying to re-enable a unique constraint. I try using this command:
alter table TESTSCHEMA_1.TEST_TABLE1 enable constraint TEST_UNIQUE_CONSTRAINT1;
The issue is that i have multiple schemas (say: TESTSCHEMA_1 to _5), and they all…

Roberto Arias
- 133
- 1
- 8
-1
votes
2 answers
Invalid Identifier in ALTER TABLE ADD COLUMN
I'm getting the error "Invalid Identifier" whilst running this ALTER TABLE statement:
ALTER TABLE TRUCK ADD COLUMN WEIGHT INTEGER NOT NULL;
The syntax is like this, so I don't understand the error:
ALTER TABLE table_name ADD COLUMN column_name…

Preeyah
- 363
- 3
- 16
- 42