本文介绍了数据库约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 如果我有桌子: 创建表格foo ( a int reference bar(id), b int引用baz(id) ) ....如何确保一列且只有一列a和b是 非空?它是否合理? ---------------------------(广播结束)----- ---------------------- 提示4:不要杀死-9''邮政局长If I have have the table:create table foo(a int references bar(id),b int references baz(id)).... how do I make sure one and only one of the columns a and b arenon-null? Is it even reasonable?---------------------------(end of broadcast)---------------------------TIP 4: Don''t ''kill -9'' the postmaster推荐答案 什么是'' ?合理" ;) BTW,id列是一个可怕的名字。最好叫它foo_id。 干杯, D - David Fetter da *** @ fetter.org http://fetter.org/ 手机:+1 510 893 6100手机:+1 415 235 3778 请记住投票! ---------------------------(播出结束)---- ----------------------- 提示3:如果通过Usenet发布/阅读,请发送适当的 subscribe-nomail命令 ma*******@postgresql.org 以便您的 消息可以干净地通过邮件列表What''s "reasonable?" ;)BTW, "id" is a terrible name for a column. Better call it foo_id.Cheers,D--David Fetter da***@fetter.org http://fetter.org/phone: +1 510 893 6100 mobile: +1 415 235 3778Remember to vote!---------------------------(end of broadcast)---------------------------TIP 3: if posting/reading through Usenet, please send an appropriatesubscribe-nomail command to ma*******@postgresql.org so that yourmessage can get through to the mailing list cleanly ALTER TABLE foo ADD CONSTRAINT must_have_a_or_b CHECK(a :: int IS NULL AND b :: int IS NOT NULL或a :: int IS NOT NULL和b :: int IS NULL); - Steven Klassen - 首席程序员 命令提示符,Inc。 - http://www.commandprompt.com/ PostgreSQL复制&支持服务,(503)667-4564 ---------------------------(结束广播)--------------------------- 提示4:不要杀人-9 ''postmasterALTER TABLE foo ADD CONSTRAINT must_have_a_or_b CHECK (a::int IS NULLAND b::int IS NOT NULL OR a::int IS NOT NULL AND b::int IS NULL);--Steven Klassen - Lead ProgrammerCommand Prompt, Inc. - http://www.commandprompt.com/PostgreSQL Replication & Support Services, (503) 667-4564---------------------------(end of broadcast)---------------------------TIP 4: Don''t ''kill -9'' the postmaster - 命令提示符,公司,Mammoth PostgreSQL的主页 - S / ODBC和S / JDBC Postgresql支持,编程共享主机和专用主机。 + 1-503-667-4564 - [email protected] - http://www.commandprompt.com Mammoth PostgreSQL Replicator。 PostgreSQL的集成复制 ---------------------------(广播结束)------ --------------------- 提示9:如果您的 $,计划员将无视您选择索引扫描的愿望b $ b加入列的数据类型不匹配--Command Prompt, Inc., home of Mammoth PostgreSQL - S/ODBC and S/JDBCPostgresql support, programming shared hosting and dedicated hosting.+1-503-667-4564 - [email protected] - http://www.commandprompt.comMammoth PostgreSQL Replicator. Integrated Replication for PostgreSQL---------------------------(end of broadcast)---------------------------TIP 9: the planner will ignore your desire to choose an index scan if yourjoining column''s datatypes do not match 这篇关于数据库约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-23 08:30