(1)
表A:id -- int identity primary key
state -- bit --状态表b
aid -- int id -- 外键,对应A的id
state -- bit
cardno -- char --身份证号码请写出SQL语句,实现将身份证号码为1234567890的会员在A、B表的状态(state)更新为2(2)
某项目经常使用到以下SQL语句进去检索:
select * from TABLE1 where col2=A and col4= B and col5=C
select * from TABLE1 where col2=A
请问如何建立索引最为合理,请简述您的理由。
表A:id -- int identity primary key
state -- bit --状态表b
aid -- int id -- 外键,对应A的id
state -- bit
cardno -- char --身份证号码请写出SQL语句,实现将身份证号码为1234567890的会员在A、B表的状态(state)更新为2(2)
某项目经常使用到以下SQL语句进去检索:
select * from TABLE1 where col2=A and col4= B and col5=C
select * from TABLE1 where col2=A
请问如何建立索引最为合理,请简述您的理由。
set state=2
where cardno='1234567890'update a
set a.state=2
from a,b
where a.id=b.aid and b.cardno='1234567890'
1.update a
set state = 2
from a,b where a.id = b.aid and cardno = '1234567890'
update b
set state = 2
where cardno = '1234567890'
bit的状态只有0和1,无法更新成2
2.
建立索引是很有学问的,单从一条select中无法确定怎么建索引
就上面的查询来看,这样建比较合理
col2建聚集索引
col4和col5建非聚集索引
表A:id -- int identity primary key
state -- bit --状态表b
aid -- int id -- 外键,对应A的id
state -- bit
cardno -- char --身份证号码请写出SQL语句,实现将身份证号码为1234567890的会员在A、B表的状态(state)更新为2
update A set state=2 from A inner join B on a.id=b.aid and b.ardno='1234567890'
update B set state=2 from B where ardno='1234567890'
(2)
某项目经常使用到以下SQL语句进去检索:
select * from TABLE1 where col2=A and col4= B and col5=C
select * from TABLE1 where col2=A
请问如何建立索引最为合理,请简述您的理由。--如果只建一个
create index idx_01 on TABLE1 (col2,col4,col5)