Creating Tables with Columns having mulitple values in SQL [duplicate]

假如想象 提交于 2020-08-20 12:55:40

问题


I've got an assignment to run some SQL queries on a table looking like this:
T1
C1| C2 | C3
x1| y1 | z1
x2| y2 | z2

But I'm not sure how to create the table in SQL.


回答1:


Are you sure is the right way to design the tables?

It look like a simple Master/Detail model

Probably your T1 table is the master

On the second table (C) put a column with reference ID to the main table

The do the query with a simple Join or Left Join




回答2:


You can create your tables using the following query: (Don't forget to have a primary key )

Create table *table 1 name *(
  *column 1 name* *properties of the column 1*,
  *column 2 name* *properties of the column 2*,
  *column 3 name* *properties of the column 3*
)

You can do the same thing with the second table that you nedd to create.

Here there is an example for you:

Create table car(
   id int primary key,
   name string,
   model string
)


来源:https://stackoverflow.com/questions/63446993/creating-tables-with-columns-having-mulitple-values-in-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!