创建表时的SQL Join表 [英] SQL Join table while creation of table

查看:92
本文介绍了创建表时的SQL Join表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建具有2列的表,这是整数columna为5且column为10.在创建此表时,我需要使colum c乘以a列,而b乘以50可以用任何方法做到


我确实在select语句中知道:
选择a列,b列((列* b列)作为"c列"

但是不能创建表.

非常感谢.

I am creating table which has 2 column , which is integer columna is 5 and column is 10. while creating this table I need to make colum c will be multiply of column a nd b will be 50 there is any way I can do that


I do know in select statement :
Select column a, column b, (columna * Column b) as ''Column c''

But not in creation of table.

Thank you very much.

推荐答案

假设您使用的是Microsoft SQL Server 2005或更高版本,则可以使用持久化的计算列.如果需要,您甚至可以为其编制索引.您的CREATE TABLE语句如下所示:
Assuming you are using Microsoft SQL Server 2005 or later, you can use a computed column that is persisted. You can even index on it if needed. Your CREATE TABLE statement would look something like this:
CREATE TABLE dbo.Test
(
   ColumnA int NOT NULL,
   ColumnB int NOT NULL,
   ColumnC AS (ColumnA * ColumnB) PERSISTED
)


现在,无论何时将值放在A和B列中,C列都会更新并存储A * B的值.

您可以在此处阅读有关如何执行此类操作的更多信息:

http://www.mssqltips.com/sqlservertip /1682/using-computed-columns-in-sql-server-with-persisted-values/ [


Now whenever you put values in columns A and B, column C will update and store the value of A*B.

You can read more information about how to do this type of thing here:

http://www.mssqltips.com/sqlservertip/1682/using-computed-columns-in-sql-server-with-persisted-values/[^]


这篇关于创建表时的SQL Join表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆