Database Operation Instance

Source: Internet
Author: User

Database Operation Instance

1 DROP TABLEMSP;2 DROP TABLEParty ;3 4 CREATE TABLEParty (PartycodeVARCHAR(Ten) not NULL5, PartynameVARCHAR( -)6, leaderVARCHAR( -)7,PRIMARY KEY(Partycode)8)DEFAULTCHARSET=UTF8;9     Ten CREATE TABLEMSP (MspnameVARCHAR( -) not NULL One, partyVARCHAR(Ten) A, constituencyVARCHAR( -) -,PRIMARY KEY(Mspname) -,FOREIGN KEY(Party)REFERENCESParty (Partycode) the)DEFAULTCHARSET=UTF8; -  - CREATE INDEXMsp_party onMSP (Party); -  + INSERT  intoPartyVALUES('Com','Communist',NULL); - INSERT  intoPartyVALUES('Con','Conservative','McLetchie MSP, David'); + INSERT  intoPartyVALUES('Green','Green',NULL); A INSERT  intoPartyVALUES('Lab','Labour','Dewar MSP, Rt Hon Donald'); at INSERT  intoPartyVALUES('LD','Liberal Democrat','Wallace QC MSP, Mr Jim'); - INSERT  intoPartyVALUES('NLP','Natural Law Party',NULL); - INSERT  intoPartyVALUES('SNP','Scottish National Party','Salmond MSP, Mr Alex'); - INSERT  intoPartyVALUES('SSP','Scottish socialist Party',NULL); - INSERT  intoPartyVALUES('SWP','Socialist Workers Party',NULL); -  in SELECT *  fromParty ; - SELECT *  fromMSP; to  + --to find a member without a political party - SELECTMspname fromMspWHEREParty is NULL; the  * --list all the political parties and leaders $ SELECTPartyname,leader fromParty ;Panax Notoginseng  - --list all political parties with a leader the SELECTPartyname fromPartyWHERELeader is  not NULL; +  A --List of Parties with at least one member the SELECTP.partyname,COUNT(M.mspname) fromParty P,msp MWHEREP.partycode=M.partyGROUP  byP.partyname having COUNT(M.mspname)>0; +   - --list the names of all the members and the party they belong to $ SELECTP.partyname,m.mspname fromParty P,msp MWHEREP.partycode=M.partyGROUP  byM.mspname; $  - --list of all political parties and the number of members of each political party - SELECT COUNT(M.mspname), P.partyname fromParty P,msp MWHEREP.partycode=M.partyGROUP  byP.partyname;


The above is an example of database operations, hoping to deepen the memory.

Database Operation Instance

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.