简体   繁体   English

如何将选择sql查询的结果转换为ms访问中的新表

[英]how to convert result of an select sql query into a new table in ms access

如何将选择sql查询的结果转换为msaccess中的新表?

You can use sub queries 您可以使用子查询

SELECT a,b,c INTO NewTable 
FROM (SELECT a,b,c
FROM TheTable
WHERE a Is Null)

Like so: 像这样:

SELECT    *
INTO      NewTable
FROM      OldTable

First, create a table with the required keys, constraints, domain checking, references, etc. Then use an INSERT INTO..SELECT construct to populate it. 首先,创建一个包含所需键,约束,域检查,引用等的表。然后使用INSERT INTO..SELECT构造来填充它。

Do not be tempted by SELECT..INTO..FROM constructs. 不要被SELECT..INTO..FROM结构诱惑。 The resulting table will have no keys, therefore will not actually be a table at all. 结果表将没有键,因此实际上根本不是表。 Better to start with a proper table then add the data eg it will be easier to trap bad data. 最好从适当的表开始然后添加数据,例如,更容易捕获坏数据。

For an example of how things can go wrong with an SELECT..INTO clause: it can result in a column that includes the NULL value and while after the event you can change the column to NOT NULL the engine will not replace the NULLs , therefore you will end up with a NOT NULL column containing NULL s! 有关SELECT..INTO子句可能出错的SELECT..INTO :它可能导致包含NULL值的列,而在事件之后您可以将列更改为NOT NULL,引擎将不会替换NULLs ,因此你将得到一个包含NULL的NOT NULL列!

Also consider creating a 'viewed' table eg using CREATE VIEW SQL DDL rather than a base table. 还可以考虑创建一个“查看”表,例如使用CREATE VIEW SQL DDL而不是基表。

If you want to do it through the user interface, you can also: 如果您想通过用户界面进行操作,还可以:

A) Create and test the select query. A)创建并测试选择查询。 Save it. 保存。

B) Create a make table query. B)创建一个make表查询。 When asked what tables to show, select the query tab and your saved query. 当询问要显示的表格时,请选择查询选项卡和保存的查询。

C) Tell it the name of the table you want to create. C)告诉它你想要创建的表的名称。

D) Go make coffee (depending on taste and size of table) D)去煮咖啡(取决于餐桌的味道和大小)

Select *
Into newtable
From somequery

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM