In sqlserver, it is impossible that if we want to create an function index. Doesn`t means we can not ?
Father said there always a way. That is virtual column.

Here is an exmple:

Sample 1
create table #checkdistribute ([CELL_ID] [varchar](20) NOT NULL)
create table #checkdistribute1 ([CELL_ID1] [varchar](2) NOT NULL)

INSERT #checkdistribute (CELL_ID) select CELL_ID from T with(nolock)
create NONCLUSTERED INDEX IDX_checkdistribute_cellid on #checkdistribute (CELL_ID asc)
INSERT #checkdistribute1 (CELL_ID1) select SUBSTRING(CELL_ID,1,2) from #checkdistribute

Although we generated an index but it still can not be use,. Because , Yes, SUBSTRING

Yes, Tables Scan.

Just wait. we also have a hope.

Sample 2

create table #checkdistribute ([CELL_ID] [varchar](20) NOT NULL,[CELL_ID_F] AS SUBSTRING(CELL_ID,1,2) )
create table #checkdistribute1 ([CELL_ID1] [varchar](2) NOT NULL)

INSERT #checkdistribute (CELL_ID) select CELL_ID from T with(nolock)
create NONCLUSTERED INDEX IDX_checkdistribute_cellid on #checkdistribute ([CELL_ID_F] asc)
INSERT #checkdistribute1 (CELL_ID1) select CELL_ID_F from #checkdistribute

It works

virtual column make sqlserver using function index的更多相关文章

  1. [oracle 11g 新特性] virtual column虚拟列

    总结:虚拟列可以使用于一些特殊场合,实质是类似于函数列(即以 表中已有的列 经过函数运算得来),“虚拟列不存储在数据库中,是在执行查询时由oracle后台计算出来返回给用户”,因此虚拟列不会增加存储空 ...

  2. Oracle 11g 虚拟列 Virtual Column介绍

    Oracle 11G 虚拟列 Virtual Column Oracle 11G 在表中引入了虚拟列,虚拟列是一个表达式,在运行时计算,不存储在数据库中,不能更新虚拟列的值. 定义一个虚拟列的语法: ...

  3. 【转】Oracle virtual column(虚拟列)

    为什么要使用虚拟列 (1)可以为虚拟列创建索引(Oracle为其创建function index) (2)可以搜集虚拟列的统计信息statistics,为CBO提供一定的采样分析. (3)可以在whe ...

  4. ajax 中$.each(json,function(index,item){ }); 中的2个参数表示什么意思?

    $.each(json,function(index,item)里面的index代表当前循环到第几个索引,item表示遍历后的当前对象,比如json数据为:[{"name":&qu ...

  5. jquery的$(selector).each(function(index,element))和$.each(dataresource,function(index,element))的区别

    $(selector).each(function(index,element)) 定义和用法 each() 方法规定为每个匹配元素规定运行的函数. $(selector).each(function ...

  6. $.each(obj,function(index,value)遍历的学习

    JQuery遍历对象 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...

  7. ORA-01733: virtual column not allowed here

    基表: hr.tt  scott.tt  视图1: 基于 hr.tt  union all  scott.tt ---> scott.ttt  视图2: 基于 视图1->scott.ttt ...

  8. $.each(data, function (index, value) { })的用法;json和list<>的互相转换

    在json中常常碰到这样的代码: jquery $.each(data, function (index, value) {    }) 遍历处理data,可以是数组.DOM.json等,取决于直接给 ...

  9. SQLServer:FUNCTION/CURSOR/PROCEDURE/TRIGGER

    一.FUNCTION:在sqlserver2008中有3中自定义函数:标量函数/内联表值函数/多语句表值函数,首先总结下他们语法的异同点:同点:1.创建定义是一样的:                  ...

随机推荐

  1. 移动端rem屏幕设置

    //修改页面title var pageTitle=document.getElementsByTagName("title")[0].innerHTML; if(location ...

  2. 浅析PHP页面局部刷新功能的实现小结(转)

    转载地址 https://www.jb51.net/article/38901.htm 方法其实挺多的.以前比较常用的是iframe这样来做.现在多了个ajax,所以一般情况下都是用的ajax.第一种 ...

  3. 【C语言】找出1000以内所有的素数

    #include<stdio.h> int main() { int i, j, t; ; i <= ; i++) { ; ; j < i; j++) { ) { t = ; ...

  4. 使用Log4net记录日志(非常重要)

    使用Log4net记录日志   首先说说为什么要进行日志记录.在一个完整的程序系统里面,日志系统是一个非常重要的功能组成部分.它可以记录下系统所产生的所有行为,并按照某种规范表达出来.我们可以使用日志 ...

  5. IDEA自动部署WEB工程至远程服务器(学习笔记)

    一.部署Web工程的几种方式 ①本地打war,上传至远程服务器tomcat容器即可 优点:简单粗暴 缺点:浪费时间 ②IDEA自动部署至远程服务器 优点:节省大量时间 缺点:配置稍多(第一次) 二.I ...

  6. How2j学习java-2、用命令行中编写第一个 JAVA 程序

    真正在工作中开发 java 应用都会使用eclipse,myeclipse, IntelliJ等等 使用最原始的命令行方式来执行Hello World 1.准备项目目录 在e: 创建一个project ...

  7. 安卓开发:用ImageView放上图片后上下有间隙

    想不到在我使用第一个UI控件ImageView时候就遇上了问题,简单使用ImageView如下: <ImageView android:layout_width="match_pare ...

  8. 记springboot 实体类String转Date类型的坑

    前端传入一个String的时间字符串如:2019-07-18 23:59:59 后端实体类要在头顶加注解: @DateTimeFormat(pattern = "yyyy-MM-dd HH: ...

  9. IPv4地址被用光,IPv6将接手

    截止2019年11月26号,全球所有43亿个IPv4地址已全部分配完毕,这一情况也宣告着IPv6时代的正式来临.IPv6和5G一样是关系到国家安全和战略发展的重大事情. IPv6简单来说,就是一个互联 ...

  10. Spring Boot JPA 使用教程

    JPA 是 Spring Boot 官方推荐的数据库访问组件,其充分体现了面向对象编程思想,有点像 asp.net 的 EFCore.JPA 也是众多 ORM 的抽象. 从本系列开始,都需要用到 my ...