JAVA-UNIT01: Database Principles, SQL (DDL, DML)

Source: Internet
Author: User

Unit01: Database Principles, SQL (DDL, DML)
SQL statements are case-insensitive, but the industry is accustomed to using keywords and sub-keywords in case of capitalization to improve readability.SELECTSysdate fromThe dualDDL statement Data definition language is used to manipulate database object database objects: tables, views, indexes, sequence creation tables:CREATE TABLEEmployee (ID Number(4), nameVARCHAR2( -), GenderCHAR(1), birth DATE, salary Number(6,2), JobVARCHAR2( -), Deptno Number(2)) View table structureDESCEmployee Delete TableDROP TABLEthe employee adds a default value option or a non-null constraint default to the field: The default keyword can be used to specify a default value for the field, regardless of what type of field is null in the database. The literal character of a string is enclosed in single quotation marks, and the literal of the string is case-sensitive.  nota NULL constraint can require that a field is not allowed to be empty. CREATE TABLEEmployee (ID Number(4), nameVARCHAR2( -) not NULL, GenderCHAR(1), birth DATE, salary Number(6,2), JobVARCHAR2( -)DEFAULT 'Clerk', Deptno Number(2) ) to modify the table1: Modify Table name2: Modify table structure Modify table name: RENAME Employee tomyempDESCmyemp Modifying table Structures2.1: Add New FieldALTER TABLEmyempADD(HireDate DATEDEFAULTsysdate)DESCmyemp2. 2 Delete an existing fieldALTER TABLEmyempDROP(HireDate)2.3: Modifying an existing field modification field is best done without data in the table. You can modify the type, length, default value, non-null. If there is data in the table, try not to type as long as possible. ALTER TABLEmyempmodify (JobVARCHAR2( +)DEFAULT 'Clerk')DESCmyempDML StatementsThe data manipulation language is used to delete data from the table and to accompany the transaction.1: inserting new dataINSERT  intomyemp (Id,name,salary,deptno)VALUES(1,'JACK', the,Ten)SELECT *  frommyemp Insert Date recommended use of To_date functionINSERT  intomyemp (Id,name,birth,salary,deptno)VALUES(2,'ROSE', To_date ('1992-08-02','YYYY-MM-DD'),  the,Ten)SELECT *  frommyemp2: Modifying the data in a table usually adds a WHERE clause to qualify the condition of the record to be modified, so that only the records that meet the criteria for where are modified, otherwise all data in the table will be modified! UPDATEmyempSETSalary=6000, Deptno= -WHEREName='JACK'3: Delete statement deletion usually also adds a WHERE clause, otherwise it clears the table operation! DELETE  frommyempWHEREName='JACK'

JAVA-UNIT01: Database Principles, SQL (DDL, DML)

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.