<?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>Acroidea &#187; SQL</title>
	<atom:link href="http://www.acroidea.com/index.php/category/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.acroidea.com</link>
	<description></description>
	<lastBuildDate>Fri, 30 Jul 2010 09:31:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Reset Identity Column Value in SQL Server (转)</title>
		<link>http://www.acroidea.com/index.php/2009/07/21/reset-identity-column-value-in-sql-server/</link>
		<comments>http://www.acroidea.com/index.php/2009/07/21/reset-identity-column-value-in-sql-server/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 14:28:41 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.acroidea.com/?p=202</guid>
		<description><![CDATA[If you are using an identity column on your SQL Server tables, you can set the next insert value to...]]></description>
			<content:encoded><![CDATA[<p>If you are using an identity column on your SQL Server tables, you can set the next insert value to whatever value you want. An example is if you wanted to start numbering your ID column at 1000 instead of 1.</p>
<p>It would be wise to first check what the current identify value is. We can use this command to do so:<br />
<pre><pre lang="sql">
DBCC CHECKIDENT (’tablename’, NORESEED)</pre></pre></p>
<p>For instance, if I wanted to check the next ID value of my orders table, I could use this command:<br />
<pre><pre lang="sql">
DBCC CHECKIDENT (orders, NORESEED)</pre></pre></p>
<p>To set the value of the next ID to be 1000, I can use this command:<br />
<pre><pre lang="sql">
DBCC CHECKIDENT (orders, RESEED, 999)</pre></pre></p>
<p>Note that the next value will be whatever you reseed with + 1, so in this case I set it to 999 so that the next value will be 1000.</p>
<p>Another thing to note is that you may need to enclose the table name in single quotes or square brackets if you are referencing by a full path, or if your table name has spaces in it. (which it really shouldn’t)<br />
<pre><pre lang="sql">
DBCC CHECKIDENT ( ‘databasename.dbo.orders’,RESEED, 999)</pre></pre></p>
]]></content:encoded>
			<wfw:commentRss>http://www.acroidea.com/index.php/2009/07/21/reset-identity-column-value-in-sql-server/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>如何选出所有子类</title>
		<link>http://www.acroidea.com/index.php/2008/10/10/%e5%a6%82%e4%bd%95%e9%80%89%e5%87%ba%e6%89%80%e6%9c%89%e5%ad%90%e7%b1%bb/</link>
		<comments>http://www.acroidea.com/index.php/2008/10/10/%e5%a6%82%e4%bd%95%e9%80%89%e5%87%ba%e6%89%80%e6%9c%89%e5%ad%90%e7%b1%bb/#comments</comments>
		<pubDate>Fri, 10 Oct 2008 02:09:02 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.acroidea.com/?p=149</guid>
		<description><![CDATA[&#8211;测试数据 CREATE   TABLE   tb(ID   char(3),PID   char(3),Name   nvarchar(10)) INSERT   tb   SELECT   &#8217;001&#8242;,NULL  ...]]></description>
			<content:encoded><![CDATA[<p>&#8211;测试数据<br />
CREATE   TABLE   tb(ID   char(3),PID   char(3),Name   nvarchar(10))<br />
INSERT   tb   SELECT   &#8217;001&#8242;,NULL   ,&#8217;山东省&#8217;<br />
UNION   ALL   SELECT   &#8217;002&#8242;,&#8217;001&#8242;,&#8217;烟台市&#8217;<br />
UNION   ALL   SELECT   &#8217;004&#8242;,&#8217;002&#8242;,&#8217;招远市&#8217;<br />
UNION   ALL   SELECT   &#8217;003&#8242;,&#8217;001&#8242;,&#8217;青岛市&#8217;<br />
UNION   ALL   SELECT   &#8217;005&#8242;,NULL   ,&#8217;四会市&#8217;<br />
UNION   ALL   SELECT   &#8217;006&#8242;,&#8217;005&#8242;,&#8217;清远市&#8217;<br />
UNION   ALL   SELECT   &#8217;007&#8242;,&#8217;006&#8242;,&#8217;小分市&#8217;<br />
GO</p>
<p>&#8211;查询指定节点及其所有子节点的函数<br />
CREATE   FUNCTION   f_Cid(@ID   char(3))<br />
RETURNS   @t_Level   TABLE(ID   char(3),Level   int)<br />
AS<br />
BEGIN<br />
DECLARE   @Level   int<br />
SET   @Level=1<br />
INSERT   @t_Level   SELECT   @ID,@Level<br />
WHILE   @@ROWCOUNT&gt;0<br />
BEGIN<br />
SET   @Level=@Level+1<br />
INSERT   @t_Level   SELECT   a.ID,@Level<br />
FROM   tb   a,@t_Level   b<br />
WHERE   a.PID=b.ID<br />
AND   b.Level=@Level-1<br />
END<br />
RETURN<br />
END<br />
GO</p>
<p>&#8211;调用函数查询002及其所有子节点<br />
SELECT   a.*<br />
FROM   tb   a,f_Cid(&#8217;002&#8242;)   b<br />
WHERE   a.ID=b.ID<br />
/*&#8211;结果<br />
ID         PID      Name<br />
&#8212;&#8212;   &#8212;&#8212;-   &#8212;&#8212;&#8212;-<br />
002      001      烟台市<br />
004      002      招远市<br />
&#8211;*/<br />
原文：http://topic.csdn.net/t/20051031/13/4361341.html</p>
]]></content:encoded>
			<wfw:commentRss>http://www.acroidea.com/index.php/2008/10/10/%e5%a6%82%e4%bd%95%e9%80%89%e5%87%ba%e6%89%80%e6%9c%89%e5%ad%90%e7%b1%bb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
