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
Sql-Only Find Time and Not Date in Access Date/Time Field
Fastest Way to Insert in Parallel to a Single Table
Database Engines and Ansi SQL Compliance
Counting Number of Joined Rows in Left Join
How to Select All Values and Hide Null Values in SQL
Misnamed Field in Subquery Leads to Join
Convert Unknown Number of Comma Separated Varchars Within 1 Column into Multiple Columns
Athena Presto - Multiple Columns from Long to Wide
Custom Order by in SQL Server Like P, A, L, H
Crosstab with 2 (Or More) Row Names
How to Represent a Many-To-Many Relationship in a Relational Database
Dynamic Pivot Queries with Dynamic Dates as Column Header in SQL Server
How to Create a SQL Table Under a Different Schema
Compress Rows with Nulls and Duplicates into Single Rows
Best Table Design for Application Configuration or Application Option Settings