最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to create a default in SQL Server and ignore the syntax errors? - Stack Overflow

programmeradmin1浏览0评论

We develop a SQL Server data recovery product. Now in a customer's database, we can get the definition of a DEFAULT object from the system base tables, as below:

CREATE DEFAULT [DF_TagTemplate_Version] AS ((1))0;

However, the definition has the following syntax error and cannot be executed:

Syntax error near '0'

So, I just wonder if there is a way to create a DEFAULT and bypass the syntax check on it?

We develop a SQL Server data recovery product. Now in a customer's database, we can get the definition of a DEFAULT object from the system base tables, as below:

CREATE DEFAULT [DF_TagTemplate_Version] AS ((1))0;

However, the definition has the following syntax error and cannot be executed:

Syntax error near '0'

So, I just wonder if there is a way to create a DEFAULT and bypass the syntax check on it?

Share Improve this question asked Jan 18 at 16:13 alanccalancc 8116 gold badges36 silver badges94 bronze badges 5
  • 1 What datatype is that column defined as? Also: this isn't just syntactically wrong - it makes no sense at all - what is the default value supposed to be really - 1 or 0 ?? – marc_s Commented Jan 18 at 16:40
  • Why do you care about defaults if you recover databases? I'm guessing you're reading the mdf files wrong – siggemannen Commented Jan 18 at 16:59
  • The DEFAULT object is due to be removed from SQL Server anyway, there's probably not much point going down this route. You'd be better off translating them to a CONSTRAINT. – Thom A Commented Jan 18 at 17:02
  • 1 As for bypassing the invalid syntax, you can't. Syntax errors fundamentally mean that the statement is broken; the interpreter cannot correctly resolve what you want to do so it fails. The solution is not the ignore the error, but fix the code. This, like your other questions, feels like an XY Problem. – Thom A Commented Jan 18 at 17:06
  • 2 How did you determine that the definition of the default in the source database was CREATE DEFAULT [DF_TagTemplate_Version] AS ((1))0? – Martin Smith Commented Jan 19 at 11:19
Add a comment  | 

1 Answer 1

Reset to default 3

"we can get the definition of a DEFAULT object from the system base tables"

You're doing that wrong, obviously. If you're mucking around in the system base tables of a corrupted database, you're on your own for correctly extracting or reconstructing the object definitions.

发布评论

评论列表(0)

  1. 暂无评论