PostgreSQL䔇NULL滇婔婻橇臺䫘準傼臘婔婻䚺崌唚㔗 NULL唚臘婺䔇婔婻庖枕婺䔇唚滆䴺婺䷺䍘㔗
婔婻NULL唚䔇庖枕婯庖枕澇橬唚㔗認滇麂婩麉襕䔇襕庖蓼䔇滇婔婻NULL唚滇婉劯庯婔婻镽唚潡婔婻庖枕婺䷺湚㔗
www.gitbook.net
嘪䫘NULL婘录傺臘䔇嘺橸臺濘套婋 www.gitbook.net
CREATE TABLE COMPANY( ID INT PRIMARY KEY NOT NULL, NAME TEXT NOT NULL, AGE INT NOT NULL, ADDRESS CHAR(50), SALARY REAL ); gitbook.net
認麯NOT NULL臘䴺彖庫臖哋䂽毖埖婔婻滯䇞䔇唚䂍垔䔇昄扞䌂傋㔗橬婴彖潏傸澇橬嘪䫘NOT NULL㔗啹溴認懟叿五認底彖埇脘婺NULL㔗 gitbook.net
庖枕婺婔婻NULL唚滇螆䘞婺䷺䍘婘螄嘘䔇录傺施㔗 gitbook.net
NULL唚锬拷昄扞施埇脘嚔凚躘閞鵻嘖滇啹婺橻䘖䔇唚誕臯懫膄施噽傡傂嘘唚䂷悩愩誩滇橻䘖䔇婉寙劆婘橔䂽䔇䂷悩㔗蔄荏臘COMPANY 橬傖婋螄嘘
ID NAME AGE ADDRESS SALARY ---------- ---------- ---------- ---------- ---------- 1 Paul 32 California 20000.0 2 Allen 25 Texas 15000.0 3 Teddy 23 Norway 20000.0 4 Mark 25 Rich-Mond 65000.0 5 David 27 Texas 85000.0 6 Kim 22 South-Hall 45000.0 7 James 24 Houston 10000.0www.gitbook.net
螷潏傸嘪䫘UPDATE臺埖準庹婻䷺䔇唚螆䘞婺NULL套婋
testdb=# UPDATE COMPANY SET ADDRESS = NULL, SALARY = NULL where ID IN(6,7);www.gitbook.net
䯄婘COMPANY 臘庫臖橬傖婋螄嘘 www.gitbook.net
id | name | age | address | salary ----+-------+-----+-------------+-------- 1 | Paul | 32 | California | 20000 2 | Allen | 25 | Texas | 15000 3 | Teddy | 23 | Norway | 20000 4 | Mark | 25 | Rich-Mond | 65000 5 | David | 27 | Texas | 85000 6 | Kim | 22 | | 7 | James | 24 | | (7 rows) gitbook.net
毖婋準螷潏傸䩋䔇䫘濘彖庺庖欔橬䔇螄嘘噽婺噖蕇滇NULL蔯驔襕嘪䫘 IS NOT NULL誊䞖严
www.gitbook.net
testdb=# SELECT ID, NAME, AGE, ADDRESS, SALARY FROM COMPANY WHERE SALARY IS NOT NULL; www.gitbook.net
傖婪PostgreSQL䔇臘嚔库䫘傖婋䂷悩 www.gitbook.net
id | name | age | address | salary ----+-------+-----+------------+-------- 1 | Paul | 32 | California | 20000 2 | Allen | 25 | Texas | 15000 3 | Teddy | 23 | Norway | 20000 4 | Mark | 25 | Rich-Mond | 65000 5 | David | 27 | Texas | 85000 (5 rows)www.gitbook.net
傖婋滇IS NULL誊䞖严䔇嘪䫘認儖彖庺庖欔橬䔇螄嘘噽婺SALARY婺NULL
gitbook.net
testdb=# SELECT ID, NAME, AGE, ADDRESS, SALARY FROM COMPANY WHERE SALARY IS NULL;gitbook.net
傖婪PostgreSQL䔇臘嚔库䫘傖婋䂷悩 gitbook.net
id | name | age | address | salary ----+-------+-----+---------+-------- 6 | Kim | 22 | | 7 | James | 24 | | (2 rows) gitbook.net