Specify Computed Columns in a Table
Before You Begin
Limitations and Restrictions
A computed column cannot be used as a DEFAULT or FOREIGN KEY constraint definition or with a NOT NULL constraint definition. However, if the computed column value is defined by a deterministic expression and the data type of the result is allowed in index columns, a computed column can be used as a key column in an index or as part of any PRIMARY KEY or UNIQUE constraint. For example, if the table has integer columns a and b, the computed column a + b may be indexed, but computed column a + DATEPART(dd, GETDATE()) cannot be indexed, because the value might change in subsequent invocations.
A computed column cannot be the target of an INSERT or UPDATE statement.
Security
Permissions
Requires ALTER permission on the table.
Using SQL Server Management Studio
To add a new computed column
In Object Explorer, expand the table for which you want to add the new computed column. Right-click Columns and select New Column.
Enter the column name and accept the default data type (nchar(10)). The Database Engine determines the data type of the computed column by applying the rules of data type precedence to the expressions specified in the formula. For example, if the formula references a column of type money and a column of type int, the computed column will be of type money because that data type has the higher precedence. For more information, see Data Type Precedence (Transact-SQL).
In the Column Properties tab, expand the Computed Column Specification property.
In the (Formula) child property, enter the expression for this column in the grid cell to the right. For example, in a
SalesTotal
column, the formula you enter might beSubTotal+TaxAmt+Freight
, which adds the value in these columns for each row in the table.Important
When a formula combines two expressions of different data types, the rules for data type precedence specify that the data type with the lower precedence is converted to the data type with the higher precedence. If the conversion is not a supported implicit conversion, the error "
Error validating the formula for column column_name.
" is returned. Use the CAST or CONVERT function to resolve the data type conflict. For example, if a column of type nvarchar is combined with a column of type int, the integer type must be converted to nvarchar as shown in this formula('Prod'+CONVERT(nvarchar(23),ProductID))
. For more information, see CAST and CONVERT (Transact-SQL).Indicate whether the data is persisted by choosing Yes or No from the drop-down for the Is Persisted child property.
On the File menu, click Savetable name.
To add a computed column definition to an existing column
In Object Explorer, right-click the table with the column for which you want to change and expand the Columns folder.
Right-click the column for which you want to specify a computed column formula and click Delete. Click OK.
Add a new column and specify the computed column formula by following the previous procedure to add a new computed column.
Specify Computed Columns in a Table的更多相关文章
- 1503 - A PRIMARY KEY must include all columns in the table's partitioning function
1503 - A PRIMARY KEY must include all columns in the table's partitioning function 错误的原因:表的主键字段必须包含分 ...
- 分区实践 A PRIMARY KEY must include all columns in the table's partitioning function
MySQL :: MySQL 8.0 Reference Manual :: 23 Partitioning https://dev.mysql.com/doc/refman/8.0/en/parti ...
- How to get the mapping relationship between two columns in a table
If a table have column A and B Count(distinct A) as Da Count(distinct B) as Db Count(distinct A, B) ...
- [转]What are mode and status columns under gp_segment_configuration table
February 16, 2017 10:39 Goal In this article we will try to understand and answer to the below two q ...
- flask启动常见问题1:sqlalchemy.exc.ArgumentError: Mapper mapped class UserCode->data_system_user_email could not assemble any primary key columns for mapped table 'data_system_user_email'
我的描述:当我编辑好flask以后,ORM映射数据库完成,启动项目时,发生现象: 解决: 看字面的意思是主键导致的错误,于是我查看了data_system_user_email的键参数配置,发现表没有 ...
- SQL Server ->> Computed Column(计算列)
Computed Column(计算列)是自SQL Server 2005开始就有的特性.计算列的定义是一个表达式.表达式可以是非计算列,常量,函数间的组合.但是不可以是子查询. 计算列数据固化 默认 ...
- Element UI table组件源码分析
本文章从如下图所示的最基本的table入手,分析table组件源代码.本人已经对table组件原来的源码进行削减,源码点击这里下载.本文只对重要的代码片段进行讲解,推荐下载代码把项目运行起来,跟着文章 ...
- 封装Vue纵向表头左右结构的table表格
我们前端开发人员在使用表格的过程中,大概率碰到的都是表格头部在表格的最上边,然后呈一行展示,紧接着就是表格的每一行的每一个单元格来展示具体内容的场景,很少会遇到表格的头部呈纵向一行展示,也就是说表格的 ...
- [转] Oracle analyze table 使用总结
转自:http://www.cnblogs.com/einyboy/archive/2012/08/09/2630321.html analyze table 一般可以指定分析: 表,所有字段,所有索 ...
随机推荐
- post方式提交数据
<!DOCTYPE HTML><html> <head> <meta charset="utf-8" /> ...
- redhat7下对用户账户的管理
redhat7对用户帐号的管理主要集中在新建,删除和修改三个动作. 1.新建用户 通过useradd --help,我们得到useradd的详细参数. -d 目录 指定用户主目录,如果此目录不存在,则 ...
- 在centos7下安装svn
SVN的安装 yum install subversion 服务端命令 1. svnserver - 控制svn系统服务的启动等 2. svnadmin - 版本库的创建/导出/导入/删除等 3. s ...
- docker学习(3)--Dockfile详解
转载请注明出处:http://www.cnblogs.com/lighten/p/6900556.html 1.基本说明 Dockfile是一个用于编写docker镜像生成过程的文件,其有特定的语法. ...
- js 的each()方法遍历对象和数组
<script src="../lib/jquery-1.8.3.min.js" ></script> <script type="text ...
- Python 列表 extend() 方法
描述 Python 列表 extend() 方法通过在列表末尾追加可迭代对象中的元素来扩展列表. 语法 extend() 方法语法: L.extend(iterable) 参数 iterable -- ...
- [LeetCode] 832. Flipping an Image_Easy
Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resu ...
- LeetCode--687. 最长同值路径
题目描述:给定一个二叉树,找到最长的路径,这个路径中的每个节点具有相同值.这条路径可以经过也可以不经过根节点.注意:两个节点之间的路径长度由它们之间的边数表示. 示例1:输入: 5 / \ 4 5 / ...
- jquery 实现iframe 自适应高度
转自: http://www.cnblogs.com/luluping/archive/2009/04/17/1437843.html 超级简单的方法,也不用写什么判断浏览器高度.宽度啥的.下面的两种 ...
- 非线性方程(组):MATLAB内置函数 solve, vpasolve, fsolve, fzero, roots [MATLAB]
MATLAB函数 solve, vpasolve, fsolve, fzero, roots 功能和信息概览 求解函数 多项式型 非多项式型 一维 高维 符号 数值 算法 solve 支持,得到全部符 ...