【问题标题】:How to add special constraints while creating table DDL创建表 DDL 时如何添加特殊约束
【发布时间】:2014-07-10 17:09:44
【问题描述】:

我想对下表中的值设置一些特殊限制:

CREATE TABLE MyTable
{
  id varchar(100) NOT NULL PRIMARY KEY,

  first_special varchar(8), <- I want it to have max of 8 symbols with no spaces in it

  second_special float  <- I want it to have precision of 2 decimal points after the '.'
}

编辑:

平台是 Microsoft SQL Server。

【问题讨论】:

  • 不要使用float(或double或类似的东西)。这些近似类型和您存储的内容不一定与您稍后检索的相同。使用 numericnumber 或 DBMS 中的任何名称。

标签: sql sql-server ddl


【解决方案1】:

在 Oracle 中(我认为在所有 dbs 中)第二个很容易。

second_special NUMBER(5,2) -- The max number would be 999.99

【讨论】:

    猜你喜欢
    • 2011-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多