各位大侠们,帮小弟解决这两个问题把:1.我刚开时建表的时候没有写入Company_ID这个主键的,后来才插进去,但是这一列放在了表的最右边,现在要把它设置为主键,但是发现
Msg 207, Level 16, State 1, Line 2
列名 'Company_ID' 无效。

这个错误,我发现怎么查找Company_ID都是无效的,不知道为什么?难道不能建好表以后插入一个列为主键吗?2.查找出Company_ID列的为null的元素是这样吗?
select *from Customers
where Company_ID=null ?

解决方案 »

  1.   

    --1主鍵列不能為空 之前的空列 你可以填充任意的不重複的值
    --2
    select *from Customers 
    where Company_ID is null 
      

  2.   

    --创建表
    create table hhhh(id int ,num int)
    --插入数据
    insert into hhhh 
    select 1,1
    --查看数据
    select * from hhhh;
    --添加一列
    alter table hhhh add m int
    --再次查看
    select * from hhhh;
    --判断为空
    select * from hhhh where m is null
    drop table hhhh
      

  3.   

    看到这个,想问问为什么判断为空了,最后还要把整个表删除掉?(drop在这里是删除的意思吧)
    select * from hhhh where m is null
    drop table hhhh
    是删除掉为空值的表还是整个表删除阿?还有个问题,这里设的主键是int格式,可以用IDENTITY[(seed,increment)]把主键设置为自动编号,但是这样一来主键就全是数字了,我想将编号写为Customer_01的格式应该就不能用自动编号了吗??   
      

  4.   

    表的主键不能为空或者为null。
    drop table 是删除整个表
    是的。自增做不到你的要求,需要在插入时自己拼字符串。