Reputation: 21
I am trying to use SQL commands to add a field called Birthday to a Customers Table. My command is
ALTER TABLE Customers ADD COLUMN Birthday
I keep getting a syntax error in the field definition. What am I doing wrong?
Upvotes: 2
Views: 231
Reputation: 349
alter TABLE Customers
ADD Birthday DATETIME
GO
update Customers set Birthday = GETDATE()
GO
alter TABLE Customers
alter column Birthday DATETIME NOT NULL
GO
alter table Customers add constraint df_Customers_note default (getDATE()) for Birthday
GO
Upvotes: 0
Reputation: 3928
You need to specify a type for the Birthday field. The syntax may depend on what the type is and which version of SQL you are using (you haven't specified either). Assuming you're using Microsoft SQL, and given that it's a birthday (and you don't need a time), and there are likely customers for whom you won't have a birthday, I'd recommend:
ALTER TABLE Customers
ADD COLUMN Birthday DATE CONSTRAINT Customers_Birthday_Default DEFAULT NULL
Upvotes: 0
Reputation: 1746
Additional column Birthday
must have it's datatype
, such as DATE
, DATETIME
etc.
ALTER TABLE Customers
ADD COLUMN Birthday DATETIME
Upvotes: 1
Reputation: 2684
You need to specity type for your column. Assuming Birthday of type DATETIME
and NOT NULL
, The syntax for adding column is:
ALTER TABLE Customers
ADD Birthday DATETIME NOT NULL
Upvotes: 1
Reputation: 6114
The query need datatype for birthday
, Ex:
ALTER TABLE Customers ADD COLUMN Birthday datetime
Upvotes: 2