Alter Table Add Column Syntax

Alter Table Add Column Syntax

Just remove COLUMN from ADD COLUMN

ALTER TABLE Employees
ADD EmployeeID numeric NOT NULL IDENTITY (1, 1)

ALTER TABLE Employees ADD CONSTRAINT
PK_Employees PRIMARY KEY CLUSTERED
(
EmployeeID
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

ADD COLUMN with CONSTRAINT

The syntax for this is

ALTER TABLE Stu_d ADD COLUMN Mobile_no INT(10) UNIQUE ;

if you want to name the constraint then use

ALTER TABLE Stu_d ADD COLUMN Mobile_no INT(10) ;
ALTER TABLE Stu_d ADD CONSTRAINT uq_Mobile_no UNIQUE (Mobile_No);

How to Add Column to an existing SQL Server table along with data

You can specify the WITH VALUES clause to apply the default constraint value to existing rows when adding the column:

ALTER TABLE dbo.LanguagePacks
ADD LgDt DATETIME NOT NULL DEFAULT GETDATE() WITH VALUES;

Alter table in mysql, add column error 1064 (42000)?

There are two different types of quotation marks in MySQL. You need to use ` for column names and ' for strings. Since you have used ' for the filename column the query parser got confused.

ALTER TABLE `cm_article` ADD COLUMN `active` INT NOT NULL DEFAULT '0' AFTER `description` ;

Syntax for Alter Column and Add Column in same query

no you need to do it in separate batches

create table test(id int)
go

alter table Test add id2 int
go
alter table Test ALTER COLUMN id DECIMAL (5, 2)

you can however add more than 1 column at a time

alter table Test add id3 int, id4 int
go


Related Topics



Leave a reply



Submit