SQL Server from getting started proficient in----table replication and multi-table connection queries

Source: Internet
Author: User

--SELECT INTO table2 from table1--INSERT INTO table2 select table1 explanationCreate Tableuserinformation (IDint Identity(10001,1), UIDint, namenvarchar( -), ageint, Birthdaynvarchar( -), Addressnvarchar( -), Countrynvarchar( -), Provincenvarchar( -), Citynvarchar( -), remarknvarchar( $),    --constraint Df_uid Foreign key (UID) references Q_user (UID))Select *  fromuserinformationAlter TableuserinformationAdd constraintDf_uidForeign Key(UID)ReferencesQ_user (UID)--assigns the Q_user query as a table to the table (with structure and data) UserInformation (requires that the table does not exist)SelectUid,uname intoUserInformation fromQ_user--inserting data from a q_user query into a userinformationInsert  intoUserInformation (Uid,name)SelectUid,uname fromQ_user--Multi-Table Query--Fully connectedSelect *   fromUserinformation,q_user--Internal ConnectionSelect *   fromQ_user b,userinformation awhereA.uid=B.uid--Inner Connection (two tables to intermediate connections, as long as the same)Select *  fromQ_user aInner JoinUserInformation b--inner can be omitted onA.uid=B.uid--left connection (based on left table, connection right with connection data, not NULL)Select *  fromQ_user a Left JoinUserInformation b--inner can be omitted onA.uid=B.uid--Right connection (based on the right table)Select *  fromQ_user a Right JoinUserInformation b--inner can be omitted onA.uid=B.uid--self-connect (just connect yourself to a table and take a different alias)Select *  fromQ_user a Right JoinQ_user b--inner can be omitted onA.uid=B.uid----------------Union----------Union unites two tables of data, and the same data shows only one of them--UNION All unites two tables, regardless of the data--either union or union all, the column names of the preceding and following tables must be consistent and the text column cannot appear-----------------Select *  fromQ_userUnion Select *  fromQ_userSelect *  fromQ_userUnion  All Select *  fromQ_user

SQL Server from getting started proficient in----table replication and multi-table connection queries

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.