Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 在SQL Server中将两个属性连接在一起_Asp.net_Sql Server_Database - Fatal编程技术网

Asp.net 在SQL Server中将两个属性连接在一起

Asp.net 在SQL Server中将两个属性连接在一起,asp.net,sql-server,database,Asp.net,Sql Server,Database,我已经将asp.net应用程序连接到SQL server数据库。但是,我的数据库中有两个属性,我想将它们连接在一起,例如: attribute 1 attribute 2 VM-Number Cloud-name 1 Azure 2 Amazon 当VM编号插入数据库时,云名称应自动插入 谢谢如果这是一个确定的键值对,您可以使用查找表 CREATE TABLE Attribute(AttrKey INT NOT

我已经将asp.net应用程序连接到SQL server数据库。但是,我的数据库中有两个属性,我想将它们连接在一起,例如:

attribute 1      attribute 2
VM-Number        Cloud-name
1                Azure
2                Amazon
当VM编号插入数据库时,云名称应自动插入


谢谢

如果这是一个确定的键值对,您可以使用查找表

CREATE TABLE Attribute(AttrKey INT NOT NULL,AttrValue VARCHAR(100));
INSERT INTO Attribute VALUES(1,'Azure'),(2,'Amazon');
然后得到相应的行,如下所示

SELECT AttrValue FROM Attribute WHERE AttrKey=1;
如果存在一个现有表“VMs”和另一个现有表“Clouds”,并且两者都有唯一的键,那么您可以使用映射表(允许m:n关系)

。。。或者将
CloudID
添加到VMs表中,或将VMID添加到Clouds表中

CREATE TABLE VM_in_Cloud(VMID INT /*your actual data type!*/ NOT NULL
                        ,CloudID INT /*your actual data type!*/ NOT NULL);