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;

  • 相关阅读:
    小学生双倍快乐
    暑期随笔
    akm
    设计原型
    测试与优化
    小学生求求你别折磨程序员
    小学生快乐刷题
    枪在手,跟我走

    第一次团队作业
  • 原文地址:https://www.cnblogs.com/java-263/p/13593964.html
Copyright © 2011-2022 走看看