Home  >  Article  >  Database  >  SQL DEFAULT 约束

SQL DEFAULT 约束

WBOY
WBOYOriginal
2016-06-07 17:38:591121browse

SQL DEFAULT 约束 今天建表时,需要向字段中插入默认值,方法如下: DEFAULT 约束用于向列中插入默认值。 如果没有规定其他的值,那么会将默认值添加到所有的新纪录。 下面的 SQL 在 "Persons" 表创建时为 "City" 列创建 DEFAULT 约束: CREATE TABLE Person

SQL DEFAULT 约束

今天建表时,需要向字段中插入默认值,方法如下:

DEFAULT 约束用于向列中插入默认值。

如果没有规定其他的值,那么会将默认值添加到所有的新纪录。


下面的 SQL 在 "Persons" 表创建时为 "City" 列创建 DEFAULT 约束:

CREATE TABLE Persons
(
Id_P int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255) DEFAULT 'Sandnes'
)
--创建数据库表login
CREATE TABLE Login       
(
    UName VARCHAR(20) PRIMARY KEY NOT NULL,
    UPassword  VARCHAR(30) NOT NULL,
    UState INT DEFAULT'0' NOT NULL
)

posted on

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn