select into from 和 insert into select 的区别和用法及 SQL SELECT INTO 中Undeclared variable错误解决办法
今天试了一下数据表中的数据备份到另一个空的数据表,然后使用了SQL SELECT INTO语句,然后提示Undeclared variable......错误,现在在这里做下总结并给出解决办法。
应用程序在开发、测试过程中,经常会遇到需要表复制的情况,比如将一个表table1的数据的部分字段或全部字段复制到表table2中,这时候就是 SELECT INTO 或者 INSERT INTO SELECT 发挥奇妙无穷的作用的时候了。至于这两种方法的区别和用法,就请慢慢往下看吧!
(1)INSERT INTO SELECT语句
语句形式为: Insert into Table2(field1,field2,,field3,...) select key1,key2,,key3,... from Table1
这种用法要求被插入的表Table2必须存在,由于被插入的表Table2已经存在,所以我们除了插入源表Table1的字段外,还可以插入我们自定义的常量。
(2)SELECT INTO FROM语句
语句形式为: SELECT key1, key2, key3 into Table2 from Table1
这种用法要求被插入的表Table2不存在,因为在插入时会自动创建表Table2,并将Table1中指定字段数据复制到Table2中。
然而今天在使用 SELECT INTO FROM 备份mysql数据表的时候,运行相关 sql 语句的时候却一直返回 [Err] 1327 - Undeclared variable: ...... 这种错误,实在不解,经过查询相关资料才知道,原来 mysql 数据库是不支持 SELECT INTO FROM 这种语句的,但是经过研究是可以通过另外一种变通的方法解决这个问题的,下面就来说说解决这个错误的办法吧!
进过搜索相关资料以及实验结果证实,可以使用
Create table Table2 (Select * from Table1);
这种语句代替
SELECT key1, key2, key3 into Table2 from Table1;
select into from 和 insert into select 的区别和用法及 SQL SELECT INTO 中Undeclared variable错误解决办法的更多相关文章
- select into from 提示 Undeclared variable.....错误的解决办法 && select into from 和 insert into select 的用法和区别
然而今天在使用 SELECT INTO FROM 备份mysql数据表的时候,运行相关 sql 语句的时候却一直返回 [Err] 1327 - Undeclared variable: ...... ...
- Access提示Insert Into 语法错误解决办法总结
1.关键字:如果你的数据库的表的设计包含了Access包含的关键字,则在插入的时候会出现“Insert Into 语法错误” 例如: string sqlText = String.Format(&q ...
- SELECT INTO FROM 与 INSERT INTO SELECT区别鉴赏
.INSERT INTO SELECT语句 语句形式为:Insert into Table2(field1,field2,...) select value1,value2,... from Tabl ...
- select into from 和 insert into select 的用法和区别
select into from 和 insert into select都是用来复制表,两者的主要区别为: select into from 要求目标表不存在,因为在插入时会自动创建.insert ...
- select into from和insert into select from两种表复制语句区别
select into from和insert into select from两种表复制语句都是将源表source_table的记录插入到目标表target_table,但两句又有区别. 第一句(s ...
- select into from 和 insert into select 的用法和区别(转)
转自:http://www.studyofnet.com/news/182.html select into from 和 insert into select都是用来复制表,两者的主要区别为: se ...
- 表复制语句select into from 与 insert into select 区别鉴赏
select into from 与 insert into select 区别鉴赏 1.INSERT INTO SELECT语句 语句形式为:Insert into Table2(field1,fi ...
- select into from 和 insert into select 的用法
SELECT INTO 和 INSERT INTO SELECT 两种表复制语句 Insert是T-sql中常用语句,Insert INTO table(field1,field2,...) valu ...
- select into from和insert into from
最近在研究oracle function 时发现select into from和insert into from,这样的语句,于是上网查阅资料学习了一下, 原来两种表达式均可以达到复制整个表或表的一 ...
随机推荐
- 使用PowerDesigner生成Access数据库
PowerDesigner生成Access数据库 自从使用PD以来一直知道可以支持access但一直没有搞明白如何通过脚本来创建access数据表.在PD的tools里终于找到的答案,具体 文件都在C ...
- 未知的系统错误(The transaction is no longer active - status: 'Committed'. No further JDBC access is allowed within this transaction.)
被调用接口处理并发能力太脆弱导致的问题. 重新请求下即可.
- Effective STL
第9条:慎重选择删除元素的方法 删除特定值元素,vector.string.deque用erase-remove:c.erase(remove(c.begin(),c.end(),1963),c.en ...
- 【转】MYSQL入门学习之七:MYSQL常用函数
转载地址:http://www.2cto.com/database/201212/175864.html 一.数学函数 www.2cto.com ABS(x) ...
- Removing Columns 分类: 贪心 CF 2015-08-08 16:10 10人阅读 评论(0) 收藏
Removing Columns time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Power Strings 分类: POJ 串 2015-07-31 19:05 8人阅读 评论(0) 收藏
Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice POJ ...
- 山东理工大学第七届ACM校赛-字符的变化 分类: 比赛 2015-06-26 10:32 46人阅读 评论(0) 收藏
字符的变化 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 一个长度为n(1<=n<=1000)的字符串(只包含小写字 ...
- (document).height()与$(window).height()区别
jQuery(window).height()代表了当前可见区域的大小,而jQuery(document).height()则代表了整个文档的高度,可视具体情况使用. 注意当浏览器窗口大小改变时(如最 ...
- 2016年11月16日 星期三 --出埃及记 Exodus 20:7
2016年11月16日 星期三 --出埃及记 Exodus 20:7 "You shall not misuse the name of the LORD your God, for the ...
- [美]莫提默 J. 艾德勒《如何阅读一本书》
我最近在阅读一本书,这本书的书名叫<如何阅读一本书>(商务出版社,2015),顾名思义. 作者认为,阅读是一件跟写书一样复杂的活动,而许多人并不会阅读. 看过后,你可能会有“我真没 ...