⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 精妙的sql语句.htm

📁 介绍SQL的书
💻 HTM
📖 第 1 页 / 共 3 页
字号:
DATEDIFF(yy,0,getdate()), 0))<BR>g. 本月的最后一天<BR>SELECT dateadd(ms,-3,DATEADD(mm, 
DATEDIFF(m,0,getdate())+1, 0))<BR>h. 本月的第一个星期一<BR>select DATEADD(wk, 
DATEDIFF(wk,0,<BR>dateadd(dd,6-datepart(day,getdate()),getdate())<BR>), 0)<BR>i. 
本年的最后一天<BR>SELECT dateadd(ms,-3,DATEADD(yy, DATEDIFF(yy,0,getdate())+1, 0))。 
</P>
<P>11.1.获取表结构[把 ’sysobjects’ 替换 成 ‘tablename’ 即可] </P>
<P>SELECT CASE IsNull(I.name, ”)<BR>When ” Then ”<BR>Else ‘*’<BR>End as 
IsPK,<BR>Object_Name(A.id) as t_name,<BR>A.name as 
c_name,<BR>IsNull(SubString(M.text, 1, 254), ”) as pbc_init,<BR>T.name as 
F_DataType,<BR>CASE IsNull(TYPEPROPERTY(T.name, ‘Scale’), ”)<BR>WHEN ” Then 
Cast(A.prec as varchar)<BR>ELSE Cast(A.prec as varchar) + ‘,’ + Cast(A.scale as 
varchar)<BR>END as F_Scale,<BR>A.isnullable as F_isNullAble<BR>FROM Syscolumns 
as A<BR>JOIN Systypes as T<BR>ON (A.xType = T.xUserType AND A.Id = 
Object_id(’sysobjects’) )<BR>LEFT JOIN ( SysIndexes as I<BR>JOIN Syscolumns as 
A1<BR>ON ( I.id = A1.id and A1.id = object_id(’sysobjects’) and (I.status &amp; 
0×800) = 0×800 AND A1.colid 0 then ‘√’ else ” end) N’主键’,<BR>b.name 
N’类型’,<BR>a.length N’占用字节数’,<BR>COLUMNPROPERTY(a.id,a.name,’PRECISION’) as 
N’长度’,<BR>isnull(COLUMNPROPERTY(a.id,a.name,’Scale’),0) as N’小数位数’,<BR>(case 
when a.isnullable=1 then ‘√’else ” end) N’允许空’,<BR>isnull(e.text,”) 
N’默认值’,<BR>isnull(g.[value],”) AS N’字段说明’<BR>FROM syscolumns a<BR>left join 
systypes b<BR>on a.xtype=b.xusertype<BR>inner join sysobjects d<BR>on a.id=d.id 
and d.xtype=’U’ and d.name’dtproperties’<BR>left join syscomments e<BR>on 
a.cdefault=e.id<BR>left join sysproperties g<BR>on a.id=g.id AND a.colid = 
g.smallid<BR>order by object_name(a.id),a.colorder </P>
<P>11.3.快速获取表test的记录总数[对大容量表非常有效] </P>
<P>快速获取表test的记录总数:<BR>select rows from sysindexes where id = object_id(‘test’) 
and indid in (0,1)</P>
<P>update 2 set KHXH=(ID+1)\2 2行递增编号<BR>update [23] set id1 = 
‘No.’+right(’00000000′+id,6) where id not like ‘No%’ //递增<BR>update [23] set 
id1= ‘No.’+right(’00000000′+replace(id1,’No.’,”),6) //补位递增<BR>delete from [1] 
where (id%2)=1<BR>奇数</P>
<P>替换表名字段<BR>update [1] set domurl = 
replace(domurl,’/upload/Imgswf/’,'/upload/Photo/’) where domurl like 
‘%/upload/Imgswf/%’</P>
<P>截位<BR>SELECT LEFT(表名, 5)</P></DIV>
<DIV class=descr>Filed under <A title=显示系统的所有文章 
href="http://zxsv.com/post/category/system" rel="category tag">系统</A> 
<STRONG></STRONG>having </DIV></DIV><!-- You can start editing here. --><A 
name=comments></A>
<H2>2 Responses</H2>
<OL class=commentlist>
  <LI class=graybox><A name=comment-508></A><CITE>busbby</CITE> Says:<BR><!--<small class="commentmetadata"><a href="#comment-508" title="星期二, 4月 4th, 2006 at 3:19 下午"></a> after publication. </small>--><SMALL 
  class=commentmetadata><A title="" 
  href="http://zxsv.com/post/168.html#comment-508">4月 4th, 2006 at 3:19 下午</A> 
  </SMALL>
  <P>据我所知<BR>SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME 
  =’&lt;TABLE&gt;’<BR>就能获得&lt;TABLE&gt;表的所有列名</P>
  <LI class=""><A name=comment-786></A><CITE><A href="http://telltruth.net/" 
  rel="external nofollow">Tian</A></CITE> Says:<BR><!--<small class="commentmetadata"><a href="#comment-786" title="星期一, 3月 5th, 2007 at 6:27 下午"></a> after publication. </small>--><SMALL 
  class=commentmetadata><A title="" 
  href="http://zxsv.com/post/168.html#comment-786">3月 5th, 2007 at 6:27 下午</A> 
  </SMALL>
  <P>只复制表结构可以用mysqldump -d 就可以</P></LI></OL><A name=respond></A>
<H3>Leave a Comment</H3>
<FORM id=commentform action=http://zxsv.com/wp-comments-post.php method=post>
<P><INPUT class=styled id=author tabIndex=1 size=22 name=author> <INPUT 
type=hidden value=168 name=comment_post_ID> <INPUT type=hidden 
value=/post/168.html name=redirect_to> <LABEL 
for=author><SMALL>Name</SMALL></LABEL></P>
<P><INPUT id=email tabIndex=2 size=22 name=email> <LABEL for=email><SMALL>Mail 
(will not be published)</SMALL></LABEL></P>
<P><INPUT id=url tabIndex=3 size=22 name=url> <LABEL 
for=url><SMALL>Website</SMALL></LABEL></P><!--<p><small><strong>XHTML:</strong> You can use these tags: &lt;a href=&quot;&quot; title=&quot;&quot;&gt; &lt;abbr title=&quot;&quot;&gt; &lt;acronym title=&quot;&quot;&gt; &lt;b&gt; &lt;blockquote cite=&quot;&quot;&gt; &lt;code&gt; &lt;em&gt; &lt;i&gt; &lt;strike&gt; &lt;strong&gt; </small></p>-->
<P><TEXTAREA id=comment tabIndex=4 name=comment rows=10 cols=100></TEXTAREA></P>
<P><SMALL><STRONG>Please note:</STRONG> Comment moderation is enabled and may 
delay your comment. There is no need to resubmit your comment.</SMALL></P>
<P><INPUT id=submit tabIndex=5 type=submit value="Submit Comment" name=submit></P></FORM>
<P align=center></P></DIV></DIV>
<DIV class=nav>
<DIV class=logo><SPAN></SPAN></DIV>
<UL>
  <LI class=current_page_item><A href="http://zxsv.com/">Home</A>
  <LI class=current_page_item><A href="http://zxsv.com/album">Album</A>
  <LI class=current_page_item><A href="http://www.spvrk.com/">Spvrk</A>
  <LI class=current_page_item><A href="http://www.ixna.net/">iXna</A></LI></UL>
<UL></UL></DIV>
<DIV class=right>
<DIV class=round>
<DIV class=roundtl><SPAN></SPAN></DIV>
<DIV class=roundtr><SPAN></SPAN></DIV>
<DIV class=clearer><SPAN></SPAN></DIV></DIV>
<DIV class=subnav>
<H1>最新文章</H1>
<UL>
  <LI><A href="http://zxsv.com/post/251.html">有什么比救人一命更重要</A>
  <LI><A href="http://zxsv.com/post/250.html">几个WM6软件绿色汉化下载</A>
  <LI><A href="http://zxsv.com/post/241.html">开源 iXNA 0.4 Bate 3 聚合程序发布</A>
  <LI><A href="http://zxsv.com/post/249.html">4月到7月的流水帐</A>
  <LI><A href="http://zxsv.com/post/248.html">没有色彩的美</A>
  <LI><A href="http://zxsv.com/post/247.html">祝他们平安!</A>
  <LI><A href="http://zxsv.com/post/246.html">utf8模板在IE下页面无端空出一行的解决方法</A>
  <LI><A href="http://zxsv.com/post/245.html">有感“脑残体”</A>
  <LI><A href="http://zxsv.com/post/244.html">“用Linux吧”[转]</A>
  <LI><A href="http://zxsv.com/post/243.html">有趣的QQ中国脸谱</A> </LI></UL><!-- START PAGES LIST --><!-- END PAGES LIST -->
<H1>分类:</H1>
<UL>
  <LI><A title=查看影音动漫下的所有文章 href="http://zxsv.com/post/category/music">影音动漫</A> 
  <LI><A title=查看杂货铺下的所有文章 href="http://zxsv.com/post/category/sundries">杂货铺</A> 

  <LI><A title=查看欣赏下的所有文章 href="http://zxsv.com/post/category/enjoy">欣赏</A> 
  <LI><A title=查看活着下的所有文章 href="http://zxsv.com/post/category/alive">活着</A> 
  <LI><A title=查看流水帐下的所有文章 href="http://zxsv.com/post/category/day">流水帐</A> 
  <LI><A title=查看灵感下的所有文章 href="http://zxsv.com/post/category/spvrk">灵感</A> 
  <LI><A title=查看系统下的所有文章 href="http://zxsv.com/post/category/system">系统</A> 
  </LI></UL>
<H1>存档:</H1>
<UL>
  <LI><A title=2007年09月 href="http://zxsv.com/post/date/2007/09">2007年09月</A> 
  <LI><A title=2007年07月 href="http://zxsv.com/post/date/2007/07">2007年07月</A> 
  <LI><A title=2007年05月 href="http://zxsv.com/post/date/2007/05">2007年05月</A> 
  <LI><A title=2007年04月 href="http://zxsv.com/post/date/2007/04">2007年04月</A> 
  <LI><A title=2007年03月 href="http://zxsv.com/post/date/2007/03">2007年03月</A> 
  <LI><A title=2007年02月 href="http://zxsv.com/post/date/2007/02">2007年02月</A> 
  <LI><A title=2007年01月 href="http://zxsv.com/post/date/2007/01">2007年01月</A> 
  <LI><A title=2006年12月 href="http://zxsv.com/post/date/2006/12">2006年12月</A> 
  <LI><A title=2006年11月 href="http://zxsv.com/post/date/2006/11">2006年11月</A> 
  <LI><A title=2006年10月 href="http://zxsv.com/post/date/2006/10">2006年10月</A> 
  <LI><A title=2006年09月 href="http://zxsv.com/post/date/2006/09">2006年09月</A> 
  <LI><A title=2006年08月 href="http://zxsv.com/post/date/2006/08">2006年08月</A> 
  <LI><A title=2006年07月 href="http://zxsv.com/post/date/2006/07">2006年07月</A> 
  <LI><A title=2006年06月 href="http://zxsv.com/post/date/2006/06">2006年06月</A> 
  <LI><A title=2006年05月 href="http://zxsv.com/post/date/2006/05">2006年05月</A> 
  <LI><A title=2006年04月 href="http://zxsv.com/post/date/2006/04">2006年04月</A> 
  <LI><A title=2006年03月 href="http://zxsv.com/post/date/2006/03">2006年03月</A> 
  <LI><A title=2006年02月 href="http://zxsv.com/post/date/2006/02">2006年02月</A> 
  <LI><A title=2006年01月 href="http://zxsv.com/post/date/2006/01">2006年01月</A> 
  <LI><A title=2005年12月 href="http://zxsv.com/post/date/2005/12">2005年12月</A> 
  <LI><A title=2005年11月 href="http://zxsv.com/post/date/2005/11">2005年11月</A> 
  <LI><A title=2005年10月 href="http://zxsv.com/post/date/2005/10">2005年10月</A> 
  <LI><A title=2005年09月 href="http://zxsv.com/post/date/2005/09">2005年09月</A> 
  <LI><A title=2005年08月 href="http://zxsv.com/post/date/2005/08">2005年08月</A> 
  <LI><A title=2005年07月 href="http://zxsv.com/post/date/2005/07">2005年07月</A> 
  <LI><A title=2005年06月 href="http://zxsv.com/post/date/2005/06">2005年06月</A> 
  <LI><A title=2005年05月 href="http://zxsv.com/post/date/2005/05">2005年05月</A> 
  <LI><A title=2005年04月 href="http://zxsv.com/post/date/2005/04">2005年04月</A> 
  <LI><A title=2005年03月 href="http://zxsv.com/post/date/2005/03">2005年03月</A> 
  </LI></UL>
<H1>搜索:</H1>
<UL>
  <LI>
  <FORM id=searchform action=/index.php method=get><INPUT id=s name=s><INPUT id=sidebarsubmit type=submit value=Search> </FORM></LI></UL>
<H1>功能:</H1>
<UL>
  <LI><A title="订阅本站 RSS" href="http://zxsv.com/feed"><ABBR 
  title="Really Simple Syndication">RSS</ABBR></A> 
  <LI><A title="所有文章的评论 RSS" href="http://zxsv.com/comments/feed">评论 <ABBR 
  title="Really Simple Syndication">RSS</ABBR></A> 
  <LI><A title="本页面符合 XHTML 1.0 Transitional 标准" 
  href="http://validator.w3.org/check/referer">标准的 <ABBR 
  title="eXtensible HyperText Markup Language">XHTML</ABBR></A> 
  <LI><A href="http://gmpg.org/xfn/"><ABBR 
  title="XHTML Friends Network">XFN</ABBR></A> </LI></UL>
<UL></UL></DIV>
<DIV class=round>
<DIV class=roundbl><SPAN></SPAN></DIV>
<DIV class=roundbr><SPAN></SPAN></DIV><SPAN class=clearer></SPAN></DIV></DIV>
<DIV class=footer>© 2006 <A href="http://zxsv.com/">剑气凌人</A> . Ported to <A 
href="http://www.wordpress.org/">Wordpress</A> by <A 
href="http://www.kaushalsheth.com/">Kaushal Sheth </A>design by <A 
href="http://arcsin.se/">Arcsin</A>. Sponsored by <A 
href="http://www.webhostingbluebook.com/">Webhostingbluebook.com</A> | <A 
href="http://www.collegepond.com/">Collegepond.com</A>
<SCRIPT src="精妙的SQL语句.files/447265.js" type=text/javascript></SCRIPT>

<SCRIPT src="精妙的SQL语句.files/urchin.js" type=text/javascript></SCRIPT>

<SCRIPT type=text/javascript>_uacct = "UA-56723-3";urchinTracker();</SCRIPT>
 </DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -