Database Notes (i)--Database basics

Source: Internet
Author: User

first, the grammar requirements1. The SQL statement can be written in single or multiple lines, ending with a semicolon. 2, you can use the space and indentation to enhance the readability of the statement. 3, the keyword is not case-sensitive, it is recommended to use uppercase. ii. Classification of sentences1.DDL(data definition Language): Defines the database object: library, table, column, index, etc. the commonly used statement keywords include create,drop,alter and so on. 2. DML (Data Manipulation Language): An operational language that defines database records (data). the commonly used statement keywords include insert,delete,udpate and so on. 3.DCL(Data Control Language): Controls the language used to define access and security levels. The main statement keywords include grant, revoke, and so on. 4.DQL(data query Language): The language for querying data. The main statement keywords include select and so on. Third, DDL statements1. Basic Library Operation(1) Create DATABASE [IF not EXISTS] Db_liu; creating a new db Db_liu,(2) show DATABASES; view all Databases(3) use Db_liu; switch to database Db_liu(4) ALTER DATABASE Db_liu CHARACTER SET UTF8;(5) Drop database [IF EXISTS] Db_liu;2. Basic table Operation(1) CREATE TABLE table name (Field Name field type, field Name field type ...); Creating a new TableNot NULL, primary key, Auto_incrementExample: CREATE TABLE User (id int,username varchar (), password varchar);(2) show TABLES; view all Tables(3) DESC table name; View Table Structure(4) Show CREATE table name \g; View Comprehensive table definition information(5) Modify the table1)ALTER table name MODIFY [column] column definition [First | After column name]; Modifying column typesExample: ALTER TABLE user modify username varchar after password;first is to change the column to column one, after password is changed to the back of the password column2)ALTER table name ADD [column] column definition [First | After Col_name]; Adding ColumnsExample: ALTER TABLE user add age int;3) ALTER table name drop [column], delete column
4)ALTER table name change [column] old column name new column definition; modify column name Example: ALTER TABLE user change username name varchar;5)ALTER TABLE name RENAME [to] new table name; 6)drop table name;Note: The change, first, and after columns are extensions of MySQL, and other databases may not haveIv. DML Statements1. Inserting DataINSERT into table name (column name 1, column Name 2, ...) Values (value 1, value 2,...);INSERT into table name values (value 1, value 2,...)2. Update DataUPDATE table name SET field1=value1,field2=value2,... [Conditional judgment];Example: Update user set username= "ABCD" where id=1; 3. Delete RecordsDELETE from table name [conditional judgment];

Database Notes (i)--Database basics

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.