如何解决消息102,级别15,状态1,行2 SQL中的语法不正确。 [英] how to solve Msg 102, Level 15, State 1, Line 2 Incorrect syntax near in SQL.

查看:268
本文介绍了如何解决消息102,级别15,状态1,行2 SQL中的语法不正确。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Team,



我想按如下方式执行此操作:

alter [FILETYPE] [int] NOT NULL DEFAULT(( 0))。



但是它给了我错误:

消息102,等级15,状态1,行2

'FILETYPE'附近的语法不正确。



请帮助我。



谢谢

Harshal

解决方案

你的语法错了



试试这个:

  ALTER   TABLE  K2FILELOG 
ADD FILETYPE int NOT NULL DEFAULT 0


尝试使用这样的语法。你错过了keyowrd SET

  ALTER  < span class =code-keyword> TABLE  TableName 
ALTER COLUMN ColumnName NOT NULL SET DEFAULT 0



让我告诉你简单方法。

如果您对此类问题感到震惊,请使用自动生成更改脚本 [ ^ ]选项


 创建  TABLE  [dbo]。[样本](
[Unique_ID] [ bigint ] NULL
[Person_ID] [ nvarchar (max)] NULL
[产品] [ nvarchar ](max) NULL
[版本] [ bigint ] NULL
[Count] [ bigint ] NULL





更改列数据类型



  ALTER   TABLE 示例
alter person_id bigint





设置现有列的默认值



alter table 示例
添加 默认 0 person_id





:)


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

解决方案

Your Syntax is wrong

Try this:

ALTER TABLE K2FILELOG
ADD FILETYPE int NOT NULL DEFAULT(0)


Try with syntax like this. You missed the keyowrd SET

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


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

ALTER TABLE sample
alter column  person_id bigint



To Set Default Value for the existing Column

alter table sample
add default 0 for person_id



:)


这篇关于如何解决消息102,级别15,状态1,行2 SQL中的语法不正确。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆