{"rsdb":{"rid":"242527","subhead":"","postdate":"0","aid":"166987","fid":"57","uid":"1","topic":"1","content":"
\n

1. SQLite \u7ea6\u675f<\/h1> \n

NOT NULL \u7ea6\u675f\uff1a\u786e\u4fdd\u67d0\u5217\u4e0d\u80fd\u6709 NULL \u503c\u3002 DEFAULT \u7ea6\u675f\uff1a\u5f53\u67d0\u5217\u6ca1\u6709\u6307\u5b9a\u503c\u65f6\uff0c\u4e3a\u8be5\u5217\u63d0\u4f9b\u9ed8\u8ba4\u503c\u3002 UNIQUE \u7ea6\u675f\uff1a\u786e\u4fdd\u67d0\u5217\u4e2d\u7684\u6240\u6709\u503c\u662f\u4e0d\u540c\u7684\u3002 PRIMARY Key \u7ea6\u675f\uff1a\u552f\u4e00\u6807\u8bc6\u6570\u636e\u5e93<\/a>\u8868\u4e2d\u7684\u5404\u884c\/\u8bb0\u5f55\u3002 CHECK \u7ea6\u675f\uff1aCHECK \u7ea6\u675f\u786e\u4fdd\u67d0\u5217\u4e2d\u7684\u6240\u6709\u503c\u6ee1\u8db3\u4e00\u5b9a\u6761\u4ef6\u3002<\/p> \n

\r\n-- \u793a\u4f8b\r\nCREATE TABLE COMPANY3(\r\n   ID           INT PRIMARY KEY     NOT NULL,\r\n   NAME         TEXT                NOT NULL,\r\n   AGE          INT                 NOT NULL UNIQUE,\r\n   ADDRESS      CHAR(50),\r\n   SALARY       REAL                CHECK(SALARY > 0)\r\n);<\/pre> \n 

2. SQLite Joins \u8054\u5408\u67e5\u8be2<\/h1> \n

SQLite \u7684 Joins \u5b50\u53e5\u7528\u4e8e\u7ed3\u5408\u4e24\u4e2a\u6216\u591a\u4e2a\u6570\u636e\u5e93\u4e2d\u8868\u7684\u8bb0\u5f55\u3002JOIN \u662f\u4e00\u79cd\u901a\u8fc7\u5171\u540c\u503c\u6765\u7ed3\u5408\u4e24\u4e2a\u8868\u4e2d\u5b57\u6bb5\u7684\u624b\u6bb5\u3002<\/p> \n

SQL \u5b9a\u4e49\u4e86\u4e09\u79cd\u4e3b\u8981\u7c7b\u578b\u7684\u8fde\u63a5\uff1a<\/p> \n

\u4ea4\u53c9\u8fde\u63a5 - CROSS JOIN \u5185\u8fde\u63a5 - INNER JOIN \u5916\u8fde\u63a5 - OUTER JOIN<\/p> \n

2.1. \u4ea4\u53c9\u8fde\u63a5 - CROSS JOIN<\/h2> \n

\u4ea4\u53c9\u8fde\u63a5\uff08CROSS JOIN\uff09\u628a\u7b2c\u4e00\u4e2a\u8868\u7684\u6bcf\u4e00\u884c\u4e0e\u7b2c\u4e8c\u4e2a\u8868\u7684\u6bcf\u4e00\u884c\u8fdb\u884c\u5339\u914d\u3002\u5982\u679c\u4e24\u4e2a\u8f93\u5165\u8868\u5206\u522b\u6709 x \u548c y \u5217\uff0c\u5219\u7ed3\u679c\u8868\u6709 x+y \u5217\u3002\u7531\u4e8e\u4ea4\u53c9\u8fde\u63a5\uff08CROSS JOIN\uff09\u6709\u53ef\u80fd\u4ea7\u751f\u975e\u5e38\u5927\u7684\u8868\uff0c\u4f7f\u7528\u65f6\u5fc5\u987b\u8c28\u614e\uff0c\u53ea\u5728\u9002\u5f53\u7684\u65f6\u5019\u4f7f\u7528\u5b83\u4eec\u3002<\/p> \n

\r\n-- \u793a\u4f8b\r\nSELECT EMP_ID, NAME, DEPT FROM table1 CROSS JOIN table2;<\/pre> \n 

2.2. \u5185\u8fde\u63a5 - INNER JOIN<\/h2> \n

\u5185\u8fde\u63a5\uff08INNER JOIN\uff09\u6839\u636e\u8fde\u63a5\u8c13\u8bcd\u7ed3\u5408\u4e24\u4e2a\u8868\uff08table1 \u548c table2\uff09\u7684\u5217\u503c\u6765\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u7ed3\u679c\u8868\u3002\u67e5\u8be2\u4f1a\u628a table1 \u4e2d\u7684\u6bcf\u4e00\u884c\u4e0e table2 \u4e2d\u7684\u6bcf\u4e00\u884c\u8fdb\u884c\u6bd4\u8f83\uff0c\u627e\u5230\u6240\u6709\u6ee1\u8db3\u8fde\u63a5\u8c13\u8bcd\u7684\u884c\u7684\u5339\u914d\u5bf9\u3002\u5f53\u6ee1\u8db3\u8fde\u63a5\u8c13\u8bcd\u65f6\uff0cA \u548c B \u884c\u7684\u6bcf\u4e2a\u5339\u914d\u5bf9\u7684\u5217\u503c\u4f1a\u5408\u5e76\u6210\u4e00\u4e2a\u7ed3\u679c\u884c\u3002<\/p> \n

\u5185\u8fde\u63a5\uff08INNER JOIN\uff09\u662f\u6700\u5e38\u89c1\u7684\u8fde\u63a5\u7c7b\u578b\uff0c\u662f\u9ed8\u8ba4\u7684\u8fde\u63a5\u7c7b\u578b\u3002INNER \u5173\u952e\u5b57\u662f\u53ef\u9009\u7684<\/p> \n

\r\n-- \u5199\u6cd51\r\nSELECT ... FROM table1 [INNER] JOIN table2 ON conditional_expression ...;\r\n\r\n-- \u5199\u6cd52\r\nSELECT ... FROM table1 JOIN table2 USING ( column1 ,... ) ...;\r\n\r\n-- \u5199\u6cd53\r\nSELECT ... FROM table1 NATURAL JOIN table2...;<\/pre> \n 
\r\nSELECT EMP_ID, NAME, DEPT FROM table1 INNER JOIN table2 ON table1.ID = table2.EMP_ID;<\/pre> \n 

2.3. \u5916\u8fde\u63a5 - OUTER JOIN<\/h2> \n

\u5916\u8fde\u63a5\uff08OUTER JOIN\uff09\u662f\u5185\u8fde\u63a5\uff08INNER JOIN\uff09\u7684\u6269\u5c55\u3002\u867d\u7136 SQL \u6807\u51c6\u5b9a\u4e49\u4e86\u4e09\u79cd\u7c7b\u578b\u7684\u5916\u8fde\u63a5\uff1aLEFT\u3001RIGHT\u3001FULL\uff0c\u4f46 SQLite \u53ea\u652f\u6301 \u5de6\u5916\u8fde\u63a5\uff08LEFT OUTER JOIN\uff09\u3002<\/p> \n

\u5916\u8fde\u63a5\uff08OUTER JOIN\uff09\u58f0\u660e\u6761\u4ef6\u7684\u65b9\u6cd5\u4e0e\u5185\u8fde\u63a5\uff08INNER JOIN\uff09\u662f\u76f8\u540c\u7684\uff0c\u4f7f\u7528 ON\u3001USING \u6216 NATURAL \u5173\u952e\u5b57\u6765\u8868\u8fbe\u3002\u6700\u521d\u7684\u7ed3\u679c\u8868\u4ee5\u76f8\u540c\u7684\u65b9\u5f0f\u8fdb\u884c\u8ba1\u7b97\u3002\u4e00\u65e6\u4e3b\u8fde\u63a5\u8ba1\u7b97\u5b8c\u6210\uff0c\u5916\u8fde\u63a5\uff08OUTER JOIN\uff09\u5c06\u4ece\u4e00\u4e2a\u6216\u4e24\u4e2a\u8868\u4e2d\u4efb\u4f55\u672a\u8fde\u63a5\u7684\u884c\u5408\u5e76\u8fdb\u6765\uff0c\u5916\u8fde\u63a5\u7684\u5217\u4f7f\u7528 NULL \u503c\uff0c\u5c06\u5b83\u4eec\u9644\u52a0\u5230\u7ed3\u679c\u8868\u4e2d\u3002<\/p> \n

\r\n-- \u5199\u6cd51\r\nSELECT ... FROM table1 LEFT OUTER JOIN table2 ON conditional_expression ...;\r\n\r\n-- \u5199\u6cd52\r\nSELECT ... FROM table1 LEFT OUTER JOIN table2 USING ( column1 ,... ) ...;<\/pre> \n 
\r\n-- \u793a\u4f8b\r\nSELECT EMP_ID, NAME, DEPT FROM table1 LEFT OUTER JOIN table2 ON table1.ID = table2.EMP_ID;<\/pre> \n 

3. SQLite Unions \u5408\u5e76<\/h1> \n

SQLite\u7684 UNION \u5b50\u53e5\/\u8fd0\u7b97\u7b26\u7528\u4e8e\u5408\u5e76\u4e24\u4e2a\u6216\u591a\u4e2a SELECT \u8bed\u53e5\u7684\u7ed3\u679c\uff0c\u4e0d\u8fd4\u56de\u4efb\u4f55\u91cd\u590d\u7684\u884c\u3002<\/p> \n

\u4e3a\u4e86\u4f7f\u7528 UNION\uff0c\u6bcf\u4e2a SELECT \u88ab\u9009\u62e9\u7684\u5217\u6570\u5fc5\u987b\u662f\u76f8\u540c\u7684\uff0c\u76f8\u540c\u6570\u76ee\u7684\u5217\u8868\u8fbe\u5f0f\uff0c\u76f8\u540c\u7684\u6570\u636e\u7c7b\u578b\uff0c\u5e76\u786e\u4fdd\u5b83\u4eec\u6709\u76f8\u540c\u7684\u987a\u5e8f\uff0c\u4f46\u5b83\u4eec\u4e0d\u5fc5\u5177\u6709\u76f8\u540c\u7684\u957f\u5ea6\u3002<\/p> \n<\/div>","orderid":"0","title":"SQLite\u7684\u9ad8\u7ea7\u7528\u6cd5\u8bb2\u89e3","smalltitle":"","mid":"0","fname":"\u6570\u636e\u5e93\u7f16\u7a0b","special_id":"0","bak_id":"0","info":"0","hits":"177","pages":"1","comments":"0","posttime":"2017-12-14 14:32:27","list":"1513233147","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"SQLite<\/A> \u9ad8\u7ea7<\/A> \u7528\u6cd5<\/A> \u8bb2\u89e3<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"113.110.149.170","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"SQLite\u7684\u9ad8\u7ea7\u7528\u6cd5\u8bb2\u89e3","lastview":"1713950480","digg_num":"0","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}