zoukankan      html  css  js  c++  java
  • Sql Server 插入数据

    --插入数据

    /*重点

    --将现有表ABC导出到一个新表ttb中。 --如果不是导出全部则可以不使用* 而使用明确列(可以导出部分列)。
    --可使用where 和groupby 等子句。
    --可联结多个表插入数据。
    --不管从多少个表中检索数据,数据都只能插入到一个表中。
    --语法: SELECT * INTO 目的表 FROM 源表
    --如果需要进行试验新SQL语句,可以使用SELECT INTO 在复制出来的表上进行测试。
    select * into ttb from abc;
    select * from ttb;


    -- 使用插入数据时 可以配合select 一起使用。
    insert into abc(id,name,aid) select id,name,cid from cba where id=9; --将CBA表中的数据插入到ABC表中, 必须保证CBA中主键或者不允许重复的列和ABC没有冲突,否则则会执行失败。


    insert into abc(id,name,aid) select id,name,cid from cba;--将CBA表中的数据插入到ABC表中, 必须保证CBA中主键或者不允许重复的列和ABC没有冲突,否则则会执行失败。

    --

    */

    insert into Customers (cust_id,cust_contact,cust_email,cust_address,cust_city,cust_state,cust_zip,cust_country) select cust_id,cust_contact,cust_email,cust_address,cust_city,cust_state,cust_zip,cust_country from custNew;


    create table cba (id int,name varchar(20),cid int)


    insert into cba values(9,'999',91)

    insert into cba values(8,'999',81)

    insert into cba values(8,'999',81)


    select * from abc


    insert into abc(id,name) select id,name from cba;


    insert into abc(id,aid) select cid,id from cba where cid=91;

  • 相关阅读:
    LINQ语句中的.AsEnumerable() 和 .AsQueryable()的区别
    Linq扩展方法之All 、Any
    Linq扩展方法之Aggregate 对序列应用累加器函数
    C#开发的进化史
    C#选择文件、选择文件夹、打开文件(或者文件夹)
    XPath操作XML文档
    文档对象模型操作xml文档
    XML简介
    php获取某经纬度附近地点位置
    Yii中实例化类的四种方式
  • 原文地址:https://www.cnblogs.com/java-263/p/13593964.html
Copyright © 2011-2022 走看看