在单个列中存储多个值

时间:2017-06-21 05:04:41

标签: sql vb.net sql-server-2014

我的表格中有两列:[Employee_idEmployee_phno]。

  • Employee_id:主键,数据类型= int
  • Employee_phno:允许null,data type = int

现在,如何在同一employee_id中插入两个电话号码?

例如:

 employee_id employee_phno()

    1        xxxxxxxxx
             yyyyyyyyyy

3 个答案:

答案 0 :(得分:2)

对我来说,如果您希望列curl_global_init(CURL_GLOBAL_ALL); CURL *myHandle; CURLcode result; struct BufferStruct output; output.buffer = NULL; output.size = 0; //requested value is on this website char* url = "https://www.somewebsite.com"; //set curl handle to write the website content into buffer myHandle = curl_easy_init(); curl_easy_setopt(myHandle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); curl_easy_setopt(myHandle, CURLOPT_WRITEDATA, (void*)&output); curl_easy_setopt(myHandle, CURLOPT_URL, url); curl_easy_perform( myHandle ); //searching for position of the requested value. uint8_t* value_position = strstr(output.buffer, "value_description"); //copy the value (8 chars) into a buffer defined earlier strncpy(value, value_position, 8); //... clean up etc. 的多个数据更好地为Employee_phno创建另一个表。在第二个表中,将外键设置为第一个表的关系。

示例:

第一桌

Employee_phno

第二桌

    Employee_id                
         1
         2
         3

在这里,您可以看到id = 2的员工有多个Employee_phno

答案 1 :(得分:0)

永远不可能在单个表中以这种方式插入数据。

答案 2 :(得分:0)

如果Employee_id是主键,那么您只能为员工创建一条记录。由于Employee_phno只有一个字段,因此无法存储2个电话号码同一名员工。

为此,您必须执行以下任一操作:

1.在数据中添加另一列Employee_Alternate_phno,如果所有员工都没有2个数字,则可以使此列允许为空。

2.创建另一个映射表,说EmployeeNumbers,其中您将EmployeeId作为外键,然后是数字字段。如果你想要2 Employee_phno,你可以随时在映射表上进行连接并检索值。

相关问题