<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>auto_increment &#8211; 記下來</title>
	<atom:link href="https://noter.tw/tag/auto_increment/feed/" rel="self" type="application/rss+xml" />
	<link>https://noter.tw</link>
	<description>一路上踩到的坑、遇到的問題，一點一滴記下來，希望能幫助到需要的人~</description>
	<lastBuildDate>Wed, 06 Nov 2019 07:12:30 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.3</generator>

<image>
	<url>https://noter.tw/wp-content/uploads/cropped-old-1130742_1920-1-32x32.jpg</url>
	<title>auto_increment &#8211; 記下來</title>
	<link>https://noter.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>SQLite 圖形化操作軟體 &#8211; SQLite Expert Personal (2)</title>
		<link>https://noter.tw/1558/sqlite-%e5%9c%96%e5%bd%a2%e5%8c%96%e6%93%8d%e4%bd%9c%e8%bb%9f%e9%ab%94-sqlite-expert-personal-2/</link>
					<comments>https://noter.tw/1558/sqlite-%e5%9c%96%e5%bd%a2%e5%8c%96%e6%93%8d%e4%bd%9c%e8%bb%9f%e9%ab%94-sqlite-expert-personal-2/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Mon, 19 Dec 2011 14:12:54 +0000</pubDate>
				<category><![CDATA[資料庫]]></category>
		<category><![CDATA[postman]]></category>
		<category><![CDATA[SQLite]]></category>
		<category><![CDATA[auto_increment]]></category>
		<category><![CDATA[gui]]></category>
		<category><![CDATA[index]]></category>
		<guid isPermaLink="false">http://wazai.co.cc/?p=1558</guid>

					<description><![CDATA[<p>小蛙在上一篇文章中介紹 SQLite Expert Personal 簡單的使用方式，這篇文章小蛙要說明怎麼設定每一筆資料都有一個可以自動新增的id，相當於Oracle的SEQUENCE，MySQL的&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/1558/sqlite-%e5%9c%96%e5%bd%a2%e5%8c%96%e6%93%8d%e4%bd%9c%e8%bb%9f%e9%ab%94-sqlite-expert-personal-2/" data-wpel-link="internal">SQLite 圖形化操作軟體 &#8211; SQLite Expert Personal (2)</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[<p>小蛙在上一篇文章中介紹 SQLite Expert Personal 簡單的使用方式，這篇文章小蛙要說明怎麼設定每一筆資料都有一個可以自動新增的id，相當於Oracle的SEQUENCE，MySQL的AUTO_INCREMENT，設定及運作方式跟MySQL的差不多，只是小蛙一開始要設定的時候還是小卡了一下。<br />
<span id="more-1558"></span><br />
這裡小蛙用實際的例子來說明，原本在設計這個資料表的時候，目的是在儲存台灣的郵遞區號，ex.台北市，大安區，Da&#8217;an Dist.,，這個資料表裡面小蛙也設定了id屬性，目的是讓比鄉鎮區以下的例如：村、里&#8230;等，可以用id來辨別是在哪個鄉鎮區。小蛙在設計到一半的時候，發現SQLite Expert Personal裡面預覽資料的時候有個欄位叫做RecNo，小蛙以為這套GUI會產生自動遞增的欄位方便使用者操作，但當小蛙透過程式存取SQLite的時候卻又得不到RecNo這個欄位的值才恍然大悟，原來這套軟體產生的RecNo只是方便使用者在GUI操作的時候辨識資料筆數。下圖是小蛙被騙的RecNo。<br />
<a href="https://noter.tw/wp-content/uploads/2011/12/sqlite-14.png" data-wpel-link="internal"><img fetchpriority="high" decoding="async" title="sqlite-14" src="https://noter.tw/wp-content/uploads/2011/12/sqlite-14.png" alt="sqlite 14 SQLite 圖形化操作軟體 - SQLite Expert Personal (2)" width="423" height="251"></a><br />
在已經建立好資料，卻又要新增not null的auto_increment欄位的方法也不難，只是做個小動作騙騙這套管理工具。在Design下的Fields頁面中選擇下方的Add，將要新增的id欄位補上，注意Type一定要用INTEGER。<br />
<a href="https://noter.tw/wp-content/uploads/2011/12/sqlite-15.png" data-wpel-link="internal"><img decoding="async" class="alignnone size-large wp-image-1563" title="sqlite-15" src="https://noter.tw/wp-content/uploads/2011/12/sqlite-15-580x419.png" alt="sqlite 15 SQLite 圖形化操作軟體 - SQLite Expert Personal (2)" width="580" height="419"></a><br />
如果上一步直接把Not null打勾的話一定會出現這個錯誤，因為已經把資料建好，而新增欄位如果是Not null，就違反了規則(新增出來的欄位裡面沒有值，當然就違反了)。<br />
<a href="https://noter.tw/wp-content/uploads/2011/12/sqlite-161.png" data-wpel-link="internal"><img decoding="async" class="alignnone size-large wp-image-1564" title="sqlite-16" src="https://noter.tw/wp-content/uploads/2011/12/sqlite-161-580x419.png" alt="sqlite 161 SQLite 圖形化操作軟體 - SQLite Expert Personal (2)" width="580" height="419"></a><br />
只要把Not null的勾勾先取消，點選OK後，繼續切換到Indexes頁面，點選下方Add後，在要自動遞增的欄位上點兩下(會跑到右邊)，之後會發現上方有三個勾，視需求勾選(Primary: PK，主要可以識別的的 Key，Unique: 唯一值，不可以重複，Autoincrement: 每一筆紀錄都會自動增加1)。確定後，點選下方的Apply就不會在出現上面的錯誤囉！<br />
<a href="https://noter.tw/wp-content/uploads/2011/12/sqlite-18.png" data-wpel-link="internal"><img decoding="async" class="alignnone size-large wp-image-1559" title="sqlite-18" src="https://noter.tw/wp-content/uploads/2011/12/sqlite-18-580x419.png" alt="sqlite 18 SQLite 圖形化操作軟體 - SQLite Expert Personal (2)" width="580" height="419"></a><br />
最後因為我們新增了Autoincrement這個屬性，因此原本新增的id欄位就不再是null，接著再回到Fields編輯剛剛的id欄位，把id欄位的Not null勾選就完成囉！<br />
最後可以把經常查詢或是需要查詢的欄位建立Index，如此一來可以加快我們搜尋資料的速度。以下這段內容節錄自<strong><a href="http://www.1keydata.com/tw/sql/sql-create-index.html" target="_blank" rel="noopener noreferrer nofollow external" data-wpel-link="external" class="wpel-icon-right">SQL語法教學<span class="wpel-icon wpel-image wpel-icon-6"></span></a></strong>。該網站舉了一個翻書的例子，如果我們在書裡有索引(可以看成是目錄)，就可以很快的找到我們要查找的資料；倘若有一本書沒有任何目錄，那麼就必須逐字去尋找。</p>
<blockquote><p>索引 (Index) 可以幫助我們從表格中快速地找到需要的資料。<br />
&#8230;<br />
從資料庫表格中尋找資料也是同樣的原理。如果一個表格沒有索引的話，資料庫系統就需要將整個表格的資料讀出 (這個過程叫做&#8217;table scan&#8217;)。若有適當的索引存在，資料庫系統就可以先由這個索引去找出需要的資料是在表格的什麼地方，然後直接去那些地方抓資料。這樣子速度就快多了。</p></blockquote>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/1558/sqlite-%e5%9c%96%e5%bd%a2%e5%8c%96%e6%93%8d%e4%bd%9c%e8%bb%9f%e9%ab%94-sqlite-expert-personal-2/" data-wpel-link="internal">SQLite 圖形化操作軟體 &#8211; SQLite Expert Personal (2)</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/1558/sqlite-%e5%9c%96%e5%bd%a2%e5%8c%96%e6%93%8d%e4%bd%9c%e8%bb%9f%e9%ab%94-sqlite-expert-personal-2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
