在SQLite中不是空字符串禁忌 [英] Not empty string contraint in SQLite

查看:138
本文介绍了在SQLite中不是空字符串禁忌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在 SQLite 中的 TEXT 列创建数据库约束,不允许列的值为空字符串

Can I create a database constraint on a TEXT column in SQLite disallowing the value of the column to be empty string ""?

我想允许该列为 null ,但不允许空字符串。

I want to allow the column to be null, but disallow empty string.

推荐答案

是的,您可以

sqlite> create table foo (bar TEXT, CHECK(bar <> ''));
sqlite> insert into foo values (NULL);
sqlite> insert into foo values ('bla');
sqlite> insert into foo values ('');
Error: constraint failed

这篇关于在SQLite中不是空字符串禁忌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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