我向视图中插入一条记录,语句写好后,命令执行成功,但是打开视图表却没有发现这条记录,而是在基本表中发现插入了这条记录,
各位高手请教,有没有方法,可以在视图中发现这条插入的记录.

解决方案 »

  1.   

    视图本身就是查找基表中的数据.create table tb(id int,col1 int,col2 int)
    go
    create view v
    as
    select * from tb
    goinsert into v values(1,2,3)select * from vdrop view v
    drop table tb
      

  2.   

    我刚才按照2楼的方法执行了一遍,还是在视图里面没有新插入的记录
    insert  
    into  IS_Student
    values ('200215129','赵新',20)select * 
    from IS_Student
      

  3.   

    create view [dbo].[IS_Student]
    as 
    select Sno,Sname,Sage
    from Student
    where Sdept='IS'; 
      

  4.   

    where   Sdept= 'IS '
    应该是被这句过滤掉了.
      

  5.   

    楼主新插入记录的Sdept的值是什么?
      

  6.   

    因为只有三个属性,所以只有学号,姓名,和年龄,'200215129 ', '赵新 ',20.
    我是觉得插入到IS_Student中,应该默认是Sdept='IS'吧
      

  7.   

    如果不指定字段的默认值,则新插入的值为NULL。
    楼主可把视图语句改为create   view   [dbo].[IS_Student] 
    as   
    select   Sno,Sname,Sage 
    from   Student 
    where   isnull(Sdept,'IS')= 'IS ';   
    试下
      

  8.   

    谢谢,楼上的,好用了,
    where   isnull(Sdept,'IS')= 'IS '; 不过这条语句起到什么作用了呢?
      

  9.   

    isnull(Sdept,'IS')的意思是判断Sdept是否为空,若为空则用'IS'代替。
    可和后面的='IS'边起来,哪位说说:
    isnull(Sdept,'IS')= 'IS '; 
    是什么意思?
      

  10.   

    等价于
          where Sdept is null
      

  11.   

    isnull(Sdept,'IS')= 'IS '
    等价于 where Sdept is null or Sdept='IS'
      

  12.   


    插入的数据不符合视图的条件
    use tempdb;create table dbo.test_tb1
    (
      bvalue int not null,
      cvalue int not null
     ) 
    insert into dbo.test_tb1
    select 13,7  union all
    select 14,9  union all
    select 14,10 union all
    select 15,8  union all
    select 16,6  union all
    select 16,14 union all
    select 17,13 union all
    select 18,17 union all
    select 17,10 ;
    go
    create view vie_test
    as
    select bvalue,cvalue
    from dbo.test_tb1
    where bvalue>15 and cvalue>12
    with check option 
    go
    insert into vie_test
    select 200,200;
    select bvalue,cvalue
    from vie_test;
    /**
    bvalue      cvalue
    ----------- -----------
    16          14
    17          13
    18          17
    200         200(4 行受影响)
    **/
    insert into vie_test
    select 17,2
    /**
    消息 550,级别 16,状态 1,第 1 行
    试图进行的插入或更新已失败,原因是目标视图或者目标视图所跨越的某一视图指定了 WITH CHECK OPTION,而该操作的一个或多个结果行又不符合 CHECK OPTION 约束。
    语句已终止。
    **/