SQL Server 默认值:为什么有一个或两个括号? [英] SQL Server default values: why with one or two parentheses?

查看:26
本文介绍了SQL Server 默认值:为什么有一个或两个括号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您运行此脚本来检索数据库中的所有默认值定义:

if you run this script to retrieve all default value definations in a database:

select 
    c.name as columnname, t.name as tablename, 
    d.definition as value, d.name as constraintname
from
    sys.default_constraints d
    join sys.columns c
        on d.parent_column_id = c.column_id
        and d.parent_object_id = c.object_id
    join sys.tables t
        on c.object_id = t.object_id

你会得到很多默认值,比如:

you would get a lot default values like:

(getdate())
((0))
('')
('2099-12-31')

我的问题是,为什么会有括号?它们是必需品吗?为什么有些值有一对,有些值有两个?编写 T-SQL 脚本时是否准确遵循计数?

My question is, why are there parentheses? Are they nessessary? Why some values have one pair of them, others have two? Is the count to be followed exactly when scripting T-SQL?

推荐答案

这就是 SQL 在内部存储它们的方式.

It's just how SQL stores them internally.

除非出于某种原因将 IN 扩展为 (.. OR ...),否则不需要它们.

They aren't needed except for when IN is expanded to (.. OR ...) for some reason.

您应该尝试使用 AND 和 OR 进行检查约束.大人大人.

You should try a check constraint with ANDs and ORs. Lordy lord.

这篇关于SQL Server 默认值:为什么有一个或两个括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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