Sql中根据旧表创建新表的SQL语句


今天在网上查了下,根据旧表创建新表的SQL语句,网上给了两个答案

create table tab_new like tab_old (使用旧表创建新表)

create table tab_new as select col1,col2… from tab_old definition only

 

两个语句都试了一下,报错了。

正确的方法是 select * into newtable from oldtable; 如果不想导记录,只想生成表结构 :select * into newtable from oldtable where 1=2;

如果newtable已存在,想导入记录:insert into newtable select * from oldtable where ...

有些也是借鉴一些其他朋友的,我在这总结一下!!

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM