﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-零雨其蒙's Blog -文章分类-SQL</title><link>http://www.blogjava.net/sslaowan/category/49285.html</link><description>做优秀的程序员</description><language>zh-cn</language><lastBuildDate>Tue, 02 Aug 2011 12:57:53 GMT</lastBuildDate><pubDate>Tue, 02 Aug 2011 12:57:53 GMT</pubDate><ttl>60</ttl><item><title> Oracle DDL和DML基本语法示例</title><link>http://www.blogjava.net/sslaowan/articles/355585.html</link><dc:creator>零雨其蒙</dc:creator><author>零雨其蒙</author><pubDate>Tue, 02 Aug 2011 05:34:00 GMT</pubDate><guid>http://www.blogjava.net/sslaowan/articles/355585.html</guid><wfw:comment>http://www.blogjava.net/sslaowan/comments/355585.html</wfw:comment><comments>http://www.blogjava.net/sslaowan/articles/355585.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/sslaowan/comments/commentRss/355585.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/sslaowan/services/trackbacks/355585.html</trackback:ping><description><![CDATA[<div><span style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><h3><div><span style="font-size: 12px; font-weight: normal; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span style="font-size: 19px; font-weight: bold; ">DDL</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><strong style="font-weight: bold; ">新建表：</strong><strong style="font-weight: bold; "><br /></strong>create table&nbsp;&nbsp;表名&nbsp;<span><br />(<br />&nbsp;</span>主键字段&nbsp;&nbsp;<span>number(15)&nbsp;&nbsp;PRIMARY KEY ,<br />&nbsp;</span>字段1&nbsp;&nbsp;nVarChar2(50) default '默认值' null /not null,<br />&nbsp;字段2 number(30) null ,<br />)<br /><strong style="font-weight: bold; ">或</strong><strong style="font-weight: bold; "></strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">create table&nbsp;&nbsp;表名&nbsp;<span><br />(<br />&nbsp;</span>主键字段&nbsp;&nbsp;<span>number(15)&nbsp;&nbsp;not null ,<br />&nbsp;</span>字段1&nbsp;&nbsp;nVarChar2(50) default '默认值' null /not null,<br />&nbsp;字段2<span>&nbsp;&nbsp;number(30) null&nbsp;&nbsp;</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">)<strong style="font-weight: bold; "></strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><strong style="font-weight: bold; ">增加主键约束</strong><strong style="font-weight: bold; "></strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">alter table&nbsp;表名</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span>&nbsp;&nbsp;add constraint&nbsp;</span>主键名&nbsp;primary key (字段名);<br /><strong style="font-weight: bold; ">删除表：</strong><strong style="font-weight: bold; "><br /></strong><strong style="font-weight: bold; "><span style="font-size: 10pt; font-family: 'Courier New'; color: navy; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">drop</span></strong>&nbsp;table [表名]<strong style="font-weight: bold; "><br /><br /><br /></strong><strong style="font-weight: bold; ">新增字段：</strong><strong style="font-weight: bold; "><br /></strong><strong style="font-weight: bold; "><span style="font-size: 10pt; font-family: 'Courier New'; color: navy; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">ALTER</span></strong>&nbsp;<strong style="font-weight: bold; "><span style="font-size: 10pt; font-family: 'Courier New'; color: navy; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">TABLE</span></strong>&nbsp;&nbsp;表名&nbsp;&nbsp;<strong style="font-weight: bold; "><span style="font-size: 10pt; font-family: 'Courier New'; color: navy; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">ADD</span></strong>字段名<span style="font-size: 10pt; font-family: 'Courier New'; color: black; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">&nbsp;&nbsp;</span>数据类型<span style="font-size: 10pt; font-family: 'Courier New'; color: black; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">&nbsp;&nbsp;default &#8216;</span>默认值<span style="font-size: 10pt; font-family: 'Courier New'; color: black; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">&#8217;&nbsp;&nbsp;null/not null</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">新增多个字段</p><p align="left" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; text-align: left; "><strong style="font-weight: bold; "><span style="font-size: 10pt; font-family: 'Courier New'; color: navy; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">ALTER</span></strong>&nbsp;<strong style="font-weight: bold; "><span style="font-size: 10pt; font-family: 'Courier New'; color: navy; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">TABLE</span></strong>&nbsp;表名</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span style="font-size: 10pt; font-family: 'Courier New'; color: black; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">&nbsp;</span><strong style="font-weight: bold; "><span style="font-size: 10pt; font-family: 'Courier New'; color: navy; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">ADD(</span></strong><strong style="font-weight: bold; "><br />&nbsp;</strong>&nbsp;<span style="font-size: 10pt; font-family: 'Courier New'; color: black; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">&nbsp;</span>字段<span style="font-size: 10pt; font-family: 'Courier New'; color: black; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">1&nbsp;&nbsp;</span>数据类型<span style="font-size: 10pt; font-family: 'Courier New'; color: black; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">&nbsp;&nbsp;default &#8216;</span>默认值<span style="font-size: 10pt; font-family: 'Courier New'; color: black; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">&#8217;&nbsp;&nbsp;null/not null,</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span style="font-size: 10pt; font-family: 'Courier New'; color: black; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">&nbsp;&nbsp;&nbsp;</span>字段<span style="font-size: 10pt; font-family: 'Courier New'; color: black; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">2&nbsp;&nbsp;</span>数据类型<span style="font-size: 10pt; font-family: 'Courier New'; color: black; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">&nbsp;&nbsp;default &#8216;</span>默认值<span style="font-size: 10pt; font-family: 'Courier New'; color: black; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">&#8217;&nbsp;&nbsp;null/not null</span><span style="font-size: 10pt; font-family: 'Courier New'; color: black; ">,</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span style="font-size: 10pt; font-family: 'Courier New'; color: black; ">&nbsp;&nbsp;&nbsp;&#8230;</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span style="font-size: 10pt; font-family: 'Courier New'; color: black; ">&nbsp;&nbsp;&nbsp;</span>字段<span style="font-size: 10pt; font-family: 'Courier New'; color: black; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">n&nbsp;&nbsp;</span>数据类型<span style="font-size: 10pt; font-family: 'Courier New'; color: black; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">&nbsp;&nbsp;default &#8216;</span>默认值<span style="font-size: 10pt; font-family: 'Courier New'; color: black; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">&#8217;&nbsp;&nbsp;null/not null</span><span style="font-size: 10pt; font-family: 'Courier New'; color: black; ">,</span><strong style="font-weight: bold; "></strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><strong style="font-weight: bold; "><span style="font-size: 10pt; font-family: 'Courier New'; color: navy; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">)</span></strong><strong style="font-weight: bold; "><br /></strong><strong style="font-weight: bold; ">删除字段：</strong><strong style="font-weight: bold; "><br /></strong>ALTER TABLE [表名] DROP COLUMN [字段名]<strong style="font-weight: bold; "><br /><br /></strong><strong style="font-weight: bold; ">修改字段：</strong><strong style="font-weight: bold; "><br /><span style="color: navy; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">ALTER TABLE&nbsp;</span></strong>[表名] ALTER COLUMN [字段名] NVARCHAR (50) NULL</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">修改多个字段</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><strong style="font-weight: bold; "><span style="color: navy; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">ALTER</span></strong>&nbsp;<strong style="font-weight: bold; "><span style="color: navy; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">TABLE&nbsp;</span></strong><strong style="font-weight: bold; ">表名</strong>&nbsp;<strong style="font-weight: bold; "><span style="color: navy; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">modify(</span></strong>字段1<span>&nbsp;&nbsp;<strong style="font-weight: bold; ">default</strong>&nbsp;'Y'<strong style="font-weight: bold; ">,</strong>&nbsp;</span>字段2&nbsp;&nbsp;<strong style="font-weight: bold; ">default</strong>&nbsp;<span style="color: blue; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">'Y'&nbsp;<strong style="font-weight: bold; ">null)</strong></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">注意：如果表的字段已经是可以为空，那么不能重复设置为可以为空。<br /><br /><strong style="font-weight: bold; ">&nbsp;</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><strong style="font-weight: bold; ">新建注释</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">表：comment on table&nbsp;表名&nbsp; is '注释';</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">字段：&nbsp; comment on column [用户名].表名.字段名&nbsp;is '注释';</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">参考：<a href="http://blog.csdn.net/liguihan88/archive/2008/09/30/3002403.aspx" style="color: #108ac6; text-decoration: underline; "><span style="color: blue; ">http://blog.csdn.net/liguihan88/archive/2008/09/30/3002403.aspx</span></a><br /><br /><br /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><strong style="font-weight: bold; "><span style="font-size: 14pt; ">DML</span></strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><strong style="font-weight: bold; ">插入数据：</strong><strong style="font-weight: bold; "><br /></strong>INSERT INTO [表名] (字段1,字段2) VALUES (100,'51WINDOWS.NET')<br /><strong style="font-weight: bold; "><br /></strong><strong style="font-weight: bold; ">删除数据：</strong><strong style="font-weight: bold; "><br /></strong>DELETE FROM [表名] WHERE [字段名]&gt;100<strong style="font-weight: bold; "><br /><br /></strong><strong style="font-weight: bold; ">更新数据：</strong><strong style="font-weight: bold; "><br /></strong><span style="font-size: 10pt; font-family: 'Courier New'; color: black; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">UPDATE [</span>表名<span style="font-size: 10pt; font-family: 'Courier New'; color: black; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">] SET [</span>字段<span style="font-size: 10pt; font-family: 'Courier New'; color: black; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">1] = 200,[</span>字段<span style="font-size: 10pt; font-family: 'Courier New'; color: black; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">2] = '51WINDOWS.NET' WHERE [</span>字段<span style="font-size: 10pt; font-family: 'Courier New'; color: black; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; ">3] = 'HAIWA'<br /><br /></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><strong style="font-weight: bold; ">其他</strong><strong style="font-weight: bold; "></strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><strong style="font-weight: bold; ">查数据库某个表的某个字段是否存在</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">SELECT&nbsp;&nbsp;*<br />FROM&nbsp;&nbsp;&nbsp; Dba_Tab_Columns&nbsp;<br />WHERE&nbsp;&nbsp; table_name&nbsp;&nbsp; = 'TABLE_NAME'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AND column_name = 'COLUMN_NAME'</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">注意表名和字段名一定大小，否则查找不到</p></span></div></h3></span></div><img src ="http://www.blogjava.net/sslaowan/aggbug/355585.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/sslaowan/" target="_blank">零雨其蒙</a> 2011-08-02 13:34 <a href="http://www.blogjava.net/sslaowan/articles/355585.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>