Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add a column to an existing table?

How can I alter a table in SQL Server Compact Edition (SQL CE)?

I have an existing table, and I need to add an IDENTITY column.

like image 411
Shiny Avatar asked May 15 '10 12:05

Shiny


People also ask

How do I add a column to an already created table?

The basic syntax of an ALTER TABLE command to add a New Column in an existing table is as follows. ALTER TABLE table_name ADD column_name datatype; The basic syntax of an ALTER TABLE command to DROP COLUMN in an existing table is as follows.

Can we add column to the existing table?

The ALTER TABLE statement is used to add, delete, or modify columns in an existing table. The ALTER TABLE statement is also used to add and drop various constraints on an existing table.

How do I add a column to an existing table without losing data?

If you use ALTER TABLE statement, it will automatically add the new column to the end of the table. The ALTER privilege is required to perform this: ALTER TABLE table_name ADD col_name data_type NULL | NOT NULL; It will not drop any existing data.


2 Answers

You add a column in the same way you would add it in other versions of SQL Server:

This adds a primary key identity column called IdColumnName to the table tableName:

ALTER TABLE tableName
ADD COLUMN IdColumnName INTEGER IDENTITY (1,1) PRIMARY KEY

See the ALTER TABLE syntax for SQL Server compact edition.

like image 118
Oded Avatar answered Sep 19 '22 16:09

Oded


Hope these examples help some one

ALTER TABLE [sales_order] ADD COLUMN  [price] MONEY NULL;
ALTER TABLE [order_details] ADD COLUMN  [price] MONEY NULL;
like image 44
samantha dias Avatar answered Sep 19 '22 16:09

samantha dias