Click here to Skip to main content
15,885,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Team,

I want to perform this as follows :
alter [FILETYPE] [int] NOT NULL DEFAULT ((0)) .

but it gives me error :
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near 'FILETYPE'.

Kindly help me .

Thanks
Harshal
Posted
Updated 23-Dec-20 3:31am
Comments
Tom Marvolo Riddle 25-Apr-14 8:30am    
do you want to alter column or table?

Your Syntax is wrong

Try this:
SQL
ALTER TABLE K2FILELOG
ADD FILETYPE int NOT NULL DEFAULT(0)
 
Share this answer
 
v2
Comments
R Harshal 25-Apr-14 8:38am    
i try this :
ALTER TABLE [dbo].[K2FILELOG]
alter column [FILETYPE] [int] NOT NULL DEFAULT ((0))

its gives me error :
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'DEFAULT'.
thatraja 25-Apr-14 8:42am    
Why 4 brackets for 0?

Try
ALTER TABLE [dbo].[K2FILELOG]
alter column [FILETYPE] [int] NOT NULL DEFAULT (0)
Tom Marvolo Riddle 25-Apr-14 8:45am    
Hi,I did the same thing which you wrote above.Still it shows the error.FYI i'm using SQL Server 2008 r2 am i missing something?
thatraja 25-Apr-14 9:08am    
It's just a guess & the syntax is wrong. Check my answer. No, I don't have SQL server to check things.
R Harshal 25-Apr-14 8:45am    
i have try but it gives me error :
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'DEFAULT'.
Try with syntax like this. You missed the keyowrd SET
SQL
ALTER TABLE TableName
ALTER COLUMN ColumnName NOT NULL SET DEFAULT 0

And let me tell you about easy way.
When you're struck on issues like this, use Auto generate change scripts[^] option
 
Share this answer
 
Comments
Tom Marvolo Riddle 25-Apr-14 9:08am    
I tried this way.But it shows the same error .Even the http://www.w3schools.com/sql/sql_default.asp[^]
shows the same syntax.But it's not working!. Any reasons?
thatraja 25-Apr-14 9:10am    
Unfortunately I don't have SQL server to check it. Better option is the link in my answer.
Tom Marvolo Riddle 25-Apr-14 9:12am    
Thanks you very much for the response thatraja!
King Fisher 26-Apr-14 1:31am    
Syntax Error: :)


Sorry We cant use alter column for default value
SQL
CREATE TABLE [dbo].[sample](
    [Unique_ID] [bigint] NULL,
    [Person_ID] [nvarchar(max)] NULL,
    [Product] [nvarchar](max) NULL,
    [Version] [bigint] NULL,
    [Count] [bigint] NULL
) 


To alter the column Datatype

SQL
ALTER TABLE sample
alter column  person_id bigint


To Set Default Value for the existing Column

SQL
alter table sample
add default 0 for person_id


:)
 
Share this answer
 
nicely explained here
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900