with check option的学习

本文详细解释了WITH CHECK OPTION的作用及影响。当创建视图时使用此选项,将限制通过视图进行的INSERT和UPDATE操作必须满足视图定义中的条件。文章还通过具体例子展示了WITH CHECK OPTION如何工作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

with check option的学习
-----------------------------------
A view is created with the following statement:
CREATE VIEW v1
AS SELECT col1, col2, col3, col4
FROM t1
WHERE col4 > 1000
WITH CHECK OPTION
What is the effect of the CHECK OPTION clause?
++++++++++++++++++++++++++++++++
 
A. Any row inserted or updated through view V1 must meet the condition that col4 > 1000.
 
student表: 
95001 李勇 男 20 CS 
95002 刘晨 女 21 IS 
95003 王敏 女 18 MA 
95004 张力 男 19 IS

建立视图IS_STUDENT显示“IS”系所有学生的学号、姓名、性别。 
create view IS_STUDENT 
as 
select Sno,Sname,Ssex 
from Student 
where Sdept='IS' 
with check option;

用insert语句向视图中插入元组('95009','王五','男'),查看基本表student表中插入的数据值。当没有加上with check option 的时候,可以成功插入,切插入到基本表的年龄和专业都是null。 当加上with check ooption 的时候,就插入失败了

通过有with check option选项的视图操作基表(只是面对单表,对连接多表的视图正在寻找答案),有以下结论: 
首先视图只操作它可以查询出来的数据,对于它查询不出的数据,即使基表有,也不可以通过视图来操作。 
1.对于update,有with check option,要保证update后,数据要被视图查询出来 
2.对于delete,有无with check option都一样 
4.对于insert,有with check option,要保证insert后,数据要被视图查询出来 
对于没有where 子句的视图,使用with check option是多余的


插入后的数据,通过视图能够查询出来就符合WITH CHECK OPTION 否则就不符合

<%@page import="com.haitaiinc.inpordnurse.ylz.dto.common.Bm_ygxx00DTO"%> <%@page import="com.haitaiinc.common.CommUtil"%> <%@ page import="com.haitaiinc.servlet.JSP,com.haitaiinc.util.Dict,com.haitaiinc.htdb.sd_haitai2.dto.*"%> <%@page import="com.haitaiinc.htdb.sd_haitai2.dto.Inpatient"%> <%@page import="com.haitaiinc.common.CommonAction"%> <%@page import="com.haitaiinc.htcpoe.InpordSystemConfig"%> <%@page import="com.haitaiinc.util.Dict"%> <%@page import="com.haitaiinc.Util"%> <%@page import="java.text.SimpleDateFormat"%> <%@page import="java.util.Calendar"%> <%@page import="java.util.Date"%> <%@page import="java.util.List"%> <%@page import="java.util.ArrayList"%> <%@page import="com.haitaiinc.servlet.JSP"%> <%@page import="com.haitaiinc.common.Const"%> <%@page import="com.haitaiinc.util.Dict"%> <%@page import="com.haitaiinc.inpordnurse.ylz.dto.yrqd.Bm_bqks00DTO"%> <jsp:useBean id="token" class="java.lang.String" scope="request"></jsp:useBean> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=7" ></meta> <%=JSP.getHtCSSDef(request)%> <%=JSP.getPageCSSDef(request) %> <%=JSP.getHtJSDef(request)%> <script src="ht-5.0/ht-core.js" type="text/javascript"></script> <script src="<%=request.getContextPath() %>/js/jquery-1.8.3.js"></script> <script src="<%=request.getContextPath() %>/js/jquery-ui-1.11.4/jquery-ui.js"></script> <link href="<%=request.getContextPath() %>/js/jquery-ui-1.11.4/jquery-ui.css" rel="stylesheet" type="text/css" /> <script src="<%=request.getContextPath() %>/js/showLoading.js"></script> <script src="<%=request.getContextPath() %>/js/orderdrug/common-edit-drug.js"></script> <script src="/nurse-business-extend/extendforylz/commjs/nurse-synthetical-oprate.js"></script> <% String titleName = "病区收入统计"; String currentTime = Util.getCurrentDate("yyyy-MM-dd"); SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd"); Calendar calendar=Calendar.getInstance(); String currentday = simpleDateFormat.format(calendar.getTime()); calendar.add(Calendar.MONTH,-1); String lastmonth = simpleDateFormat.format(calendar.getTime()); //医嘱检索结果区下方增加空白区域显示医嘱的特殊说明 String showDesc = "false"; showDesc = "true"; List<Bm_bqks00DTO> bqksList = (ArrayList)request.getAttribute("bqksList"); List<Bm_ygxx00DTO> yhryList = (ArrayList)request.getAttribute("yshsList"); String[] monthsList = {"1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"}; %> <title><%=titleName%></title> <script type="text/javascript" src="js/json2.js"></script> <script type="text/javascript"> </script> <style> html{height:100%;overflow:hidden;} .div-radio { margin: 0px 0px 0px 0px; } .div-inline1{ margin-top: 5px; margin-left: -6px; padding-left: 10px; height: 25px; } </style> </head> <body style="height:100%"> <div id="qrDiv" style="height:100%;"> <form name="searchForm" id="searchForm" method="post"> <table cellpadding="1" cellspacing="1" style="table-layout: fixed;width: 100%; height:100%;"> <colgroup> <col id="colId" width="100%"> </colgroup> <tr> <td class="main_bg_search" style="width: 100%;" colspan="2"> <table width="100%" border="0" cellpadding="0" cellspacing="0" align="center"> <tr> <td> <div class="div-inline">  科室: <select id="bqks" name="bqks" style="width: 120px;height: 23px;" onchange="changeYhry(this);"> <option selected="selected" value="">全部</option> <% for(int j=0; bqksList!=null&&j<bqksList.size();j++){ Bm_bqks00DTO sd = bqksList.get(j); %> <option value="<%=Util.toString(sd.getKsh000()) %>"><%=Util.toString(sd.getBmmc00()) %></option> <%} %> </select> </div>  <div class="div-inline"> <span> <label><input type="radio" style="margin-left: -10px;" name="itemStatus" value="xmlb" checked="checked" onclick="checkYhry(this);searchList();"/>按项目类别</label> <label><input type="radio" name="itemStatus" value="jtxm" onclick="checkYhry(this);searchList();" />按具体项目</label> <label><input type="radio" name="itemStatus" value="yhry" onclick="checkYhry(this);searchList();" /> 按医护人员: <select id="yhry" name="yhry" disabled="disabled" style="width: 120px;height: 23px;"> <option selected="selected" value="">全部</option> <% for(int j=0; yhryList!=null&&j<yhryList.size();j++){ Bm_ygxx00DTO sd = yhryList.get(j); %> <option value="<%=Util.toString(sd.getYgbh00()) %>"><%=Util.toString(sd.getZwxm00()) %></option> <%} %> </select> </label> </span> </div>  </td> </tr> <tr> <td>    <div class="div-inline div-checkbox-or-radio div-inline1"> <span> <label><input type="radio" checked="checked" style="margin-left: -10px;" name="timeTypes" value="0" onclick="checkTime(this);"/> 月份: <select id="months" name="months" style="width: 120px;height: 22px;margin-top: 1px;"> <option selected="selected" value="0">当前月份</option> <% for(int j=0; monthsList!=null&&j<monthsList.length;j++){ %> <option value="<%=j+1 %>"><%=monthsList[j] %></option> <%} %> </select> </label> </span> </div>   <div class="div-inline div-checkbox-or-radio div-inline1" style="margin-bottom: 3px;"> <span> <label><input type="radio" style="margin-left: -10px;" name="timeTypes" value="1" onclick="checkTime(this);"/> 时间: <input type="text" readonly name="startTime" id="startTime" style="width: 100px;" disabled="disabled" onclick="fPopUpCalendarDlg(startTime);searchList();" value="<%=Util.format(lastmonth, "yyyy-MM-dd")%>" /> - <input type="text" readonly name="endTime" id="endTime" style="width: 100px;" disabled="disabled" onclick="fPopUpCalendarDlg(endTime);searchList();" value="<%=Util.format(currentday, "yyyy-MM-dd")%>" /> </label> </span> </div> <div class="div-inline" style="margin-bottom: 5px;"> <input type="button" class="order_button" value="查  询" id='queryBtn' onclick="searchList();"/>   <input type="button" class="order_button" value="导出Excel" id='exportExcelBtn' onclick="exportExcel();"/>   </div> </td> </tr> </table> </td> </tr> <tr id="listTr"> <td id="dataTd" height="84.5%" width="100%" align="left" valign="top"> <table cellpadding="1" cellspacing="1" style="table-layout: fixed;width: 100%; height:100%;"> <tr> <td height="100%" width="100%" ><!-- 医嘱信息展示列表区 --> <div id="listshow" style="overflow:hidden;height:100%;width:100%;" ></div> </td> </tr> </table> </td> </tr> </table> </form> </div> <div id="swElement" style="display: none;"> </div> </body> <script type="text/javascript"> var token = "<%=token%>"; var menu = "<%=titleName%>"; searchList(); //展示统计列表 function searchList(){ showLoading(); var url = "do?module=inpordnurse&action=YlzBqsrtj&method=searchIncomeStatisticsList"; $("#listshow").html(""); Haitai.Ajax.request({ url : url, params:{ token:token }, form : searchForm, callback : function(text){ closeLoading(); ht("listshow").html(text,false); } }); } function checkYhry(obj){ if(obj.value=="xmlb"&&obj.checked){ $("#yhry").attr("disabled",true); }else if(obj.value=="jtxm"&&obj.checked){ $("#yhry").attr("disabled",true); }else{ $("#yhry").attr("disabled",false); } } function checkTime(obj){ if(obj.value=="0"&&obj.checked){ $("#startTime").attr("disabled",true); $("#endTime").attr("disabled",true); $("#months").attr("disabled",false); }else{ $("#startTime").attr("disabled",false); $("#endTime").attr("disabled",false); $("#months").attr("disabled",true); } searchList(); } function checkIsNull(str){ if(str==null||str==""||str==undefined){ return true; }else{ return false; } } //选择科室联动变化医护人员下拉框数据,护士不变,医生随科室切换变化 function changeYhry(obj){ var xzks00 = obj.value; if(xzks00!=""){ var url = "do?module=inpordnurse&action=YlzBqsrtj&method=searchYhryByXzks"; Haitai.Ajax.request({ url : url, params:{ token:token, xzks00:xzks00 }, form : searchForm, callback : function(text){ if(checkIsNull(text)){ var yhryObj = $("#yhry"); yhryObj.html(""); yhryObj.append($("<option selected=\"selected\" value=\"\">全部</option>")); }else{ var retJson = eval("("+text+")"); var yhryObj = $("#yhry"); yhryObj.html(""); yhryObj.append($("<option selected=\"selected\" value=\"\">全部</option>")); for(var i=0;i<retJson.length;i++){ yhryObj.append($("<option value=\""+retJson[i].ygbh00+"\">"+retJson[i].zwxm00+"</option>")); } } } }); } } function exportExcel(){ } </script> </html>exportExcel帮我导出excel
最新发布
07-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值