SQL server從入門精通----表的複製與多表串連查詢

來源:互聯網
上載者:User

標籤:

--select into table2 from table1--insert into  table2 select table1  講解create table userInformation(    id int identity(10001,1),    uid int,    name nvarchar(30),    age int,    birthday nvarchar(30),    address nvarchar(50),    country nvarchar(20),    province nvarchar(20),    city nvarchar(20),    remark nvarchar(200),    --constraint DF_uid Foreign key(uid) references Q_user(uid))select * from userInformationalter table userInformationadd constraint DF_uid Foreign key(uid) references Q_user(uid)--將 Q_user 查詢的當作表賦值給表(含結構和資料) userInformation(要求此表不存在)select uid,uName into userInformation from Q_user  --將Q_user查詢的資料插入到 userInformationinsert into  userInformation(uid,name) select uid,uName from Q_user--多表查詢--全串連select *  from userInformation,Q_user --內串連select *  from Q_user b,userInformation awhere a.uid=b.uid --內串連(兩張 表向中間串連,只要相同的)select * from Q_user ainner join userInformation b   --inner 可以省略on a.uId=b.uid--左串連   (以左邊的表為基礎,串連右邊有串連資料,沒有為null)select * from Q_user aleft join userInformation b   --inner 可以省略on a.uId=b.uid--右串連(以右邊的表為基礎)select * from Q_user aright join userInformation b   --inner 可以省略on a.uId=b.uid--自串連(就是串連自己 給一張表取不同的別名就好了)select * from Q_user aright join Q_user b   --inner 可以省略on a.uId=b.uid----------------union----------union 聯合兩張表的資料,相同資料只顯示其中的一條--union all 完全將兩張表聯合,不管資料的相同--不管是union還是union all,前表與後表的列名一定要是一致的,而且不能出現text的列-----------------select * from Q_user union select * from Q_user  select * from Q_user union all select * from Q_user 

 

SQL server從入門精通----表的複製與多表串連查詢

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.