`
ispring
  • 浏览: 355616 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

关于MySQL select into 和 SQLServer select into

阅读更多

关于MySQL select into 和 SQLServer select into


一.MySQL不支持Select Into语句直接备份表结构和数据,由于工作中的需要在网上找到一种方法可以代替, 也有其它方法可以处理,总结如下:

方法1:
     MYSQL不支持:
        Select * Into new_table_name from old_table_name;
     替代方法:
        Create table new_table_name (Select * from old_table_name);


方法2:
     1.先备份表结构和数据
#导出命令 -u用户名 -p密码 -h主机IP地址 数据库名 表名1   > 导出文件.sql
mysqldump -uroot -proot -h192.168.0.88 ok_db oktable2 > ok_db.sql

     2.修改备份表的名字
     3.登录MySQL
     4.选择数据库
     5.执行: Source 备份表的路径 如:Source d:\ok_db.sql 回车即可。
     6.完成.


二. SQLServer支持 Select into语句
   1.备份表直接执行如下就可以了。
      Select * Into new_table_name from old_table_name;


三. MySQL Select into outfile用于导出指定的查询数据到文件如下:

1.导出表中所有数据到C盘根目录outfile.txt中如下:
     Select * into outfile 'c:\\outfile.txt' from test;

  
2.导出表中指定查询条件2005-06-08号的数据到C盘根目录outfile1.txt中如下:
     Select * into outfile 'c:\\outfile.txt' from test where beginDate='2008-06-08';

分享到:
评论

相关推荐

    MYSQL,SQLSERVER,ORACLE常用的函数

    SQL> select ascii('A') A,ascii('a') a,ascii('0') zero,ascii(' ') space from dual; A A ZERO SPACE --------- --------- --------- --------- 65 97 48 32 2.CHR 给出整数,返回对应的字符; SQL> select ...

    my sql与sql server实时同步源码,自定义设置同步时间

    //本程序的功能是实时从mysql中读取一条记录中的一个字段,插入到sqlserver 中,经过长时间的运行,基本无错了, 而这数据同步,目前没有实时性强的软件,至少1分钟,太久了,自己写了一个, //可以自己设置同步时间...

    java(myeclipse10)连接数据库sqlserver2008的实例

    这是一个sqlserver 2008连接的完整实例; 在sqlserver 2008中创建名为 yanwen 数据库 建一张user表 代码如下 INSERT INTO [yanwen].[dbo].[users] ([name] ,[password] ,[age]) VALUES ('cyw' ,'123456' ,...

    insert和select结合实现”插入某字段在数据库中的最大值+1″的方法

    本文是mysql 数据库 问题一 将表一的数据导入表二...在表中插入数据时,某一字段取数据库中该字段的最大值,并+1,这个问题很多人都说用存储过程什么的解决,其实使用insert 和 select 结合就可以很好的解决这个问题啊

    浅析MySQL replace into 的用法

    在 SQL Server 中可以这样处理: 代码如下: if not exists (select 1 from t where id = 1) insert into t(id, update_time) values(1, getdate())else update t set update_time = getdate() where id = 1 那么...

    MYSQL

    5.1 MySQL对ANSI SQL92 的扩充 5.2 以ANSI模式运行 MySQL 5.3 MySQL相比ANSI SQL92的差别 5.4 MySQL 缺乏的功能 5.4.1 子选择(Sub-selects) 5.4.2 SELECT INTO TABLE 5.4.3 事务...

    MySQL中replace into语句的用法详解

    在 SQL Server 中可以这样写: 代码如下: if not exists (select 1 from table where id = 1) insert into table(id, update_time) values(1, getdate()) else update table set update_time = getdate() where id ...

    MySQL中文参考手册

    + 5.4.2 SELECT INTO TABLE + 5.4.3 事务(Transactions) + 5.4.4 存储过程和触发器 + 5.4.5 外键(Foreign Keys) # 5.4.5.1 不使用外键的理由 + 5.4.6 视图(Views) + 5.4.7 '--'作为一个 注解的开始 o 5.5 ...

    MySQL中文参考手册.chm

    5.1 MySQL对ANSI SQL92 的扩充 5.2 以ANSI模式运行 MySQL 5.3 MySQL相比ANSI SQL92的差别 5.4 MySQL 缺乏的功能 5.4.1 子选择(Sub-selects) 5.4.2 SELECT INTO TABLE 5.4.3 事务...

    mysql数据库的基本操作语法

    insert into temp(name) select name from classes; 多行插入 insert into temp values(null, ‘jack’, 22), (null, ‘jackson’ 23); 2、 update 修改语句 update主要完成对数据的修改操作,可以修改一条或多...

    Oracle 实现类似SQL Server中自增字段的一个办法

    相关代码如下: 1. 创建sequence: 代码如下:CREATE SEQUENCE SEQU_DATA_DATAINFO INCREMENT BY 1 START WITH 1 NOCYCLE NOCACHE NOORDER;... Select SEQU_PROC_ASSOCIATEINFO.NextVal into tmpVar f

    深入Mysql,SqlServer,Oracle主键自动增长的设置详解

    1、把主键定义为自动增长标识符类型MySql在mysql中,如果把表的主键设为auto_increment类型,数据库就会自动为主键赋值。例如: 代码如下:create table customers(id int auto_increment primary key not null, name...

    MySQL+Cookbook.

     Use SQL to select, sort, and summarize rows  Find matches or mismatches between rows in two tables  Determine intervals between dates or times, including age calculations  Store images into ...

    Sql for mysql

    4.2 Logging On to the MySQL Database Server . . . . . . . . . . . . . . . 41 4.3 Creating New SQL Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 4.4 Creating Databases . . . . . . ...

    SQL Server2008中删除重复记录的方法分享

    现在让我们来看在SQL SERVER 2008中如何删除这些记录, 首先,可以模拟造一些简单重复记录: 代码如下: Create Table dbo.Employee ( [Id] int Primary KEY , [Name] varchar(50), [Age] int, [Sex] bit default 1 ) ...

    经典全面的SQL语句大全

    Sql server:select top n * from 表名 order by newid() mysql select * From 表名 Order By rand() Limit n  Access左连接语法(最近开发要用左连接,Access帮助什么都没有,网上没有Access的SQL说明,只有自己测试, ...

    t_book(从mysql下载查询结果的数据库表)

    从mysql下载查询结果的数据库表,对应的sql为 ...into outfile 'C:/ProgramData/MySQL/MySQL Server 5.7/Uploads/t_book.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\r\n'

    MySQL 入门学习 ——基础教程

    如果出现 "ERROR 2003: Can´t connect to MySQL server on ´localhost´ (10061)“, 说明你的MySQL还没有启动。 · 3、退出MySQL操作界面 在mysql>提示符下输入quit可以随时退出交互操作界面: mysql> quit ...

    sqlserver利用存储过程去除重复行的sql语句

    还是先上代码吧 ,可以先看 SQL语句去掉重复记录,获取重复记录 代码....[dbo].[testim] –删除表 –把不重复记录转存到testim中 select * into [ItemMaster].[dbo].[testim] from [ItemMaster].[dbo].[dat_item_maste

Global site tag (gtag.js) - Google Analytics