## What is MySql database? Its basic usage

In short database is stored data warehouse, is a collection of data in order to achieve a certain purpose, according to certain rules organized.

So we have a common database model:

1, a relational database

  MySql

  Oracle

  SQL Server

2, non-relational database

  2,1 document storage database MongDB

  2,2 key-value store database Redis Memcached

  2, 3, column-store database HBase

  2,4 graphical database Neo4J

About database in the company subject of the interview are those who do?

  1, SQL database operation statement

  2, SQL statement action table structure

  3, the relationship between the attributes and the relationships between fields and tables class

Table corresponding to the java classes, the database used to store data fetched

Field name (column) and class member variables of the same properties

Objects rows in a table created from class

3, SQL statement presentation:

  MySql do not know java, then you need to interact with the database required to know the language

  SQL statement is a data code library

4, SQL classification

  4,1 Data Definition Language DDL for a database table definitions and column Keywords: create alter drop

  4,2 database operations DML statement is used to update the keyword database tables: insert delete updata

  4,3 DCL statement Database control for database access permissions and security levels  

  4,4 DQL query the database for records subject keyword: select from where

5, SQL general syntax:

  1, case-insensitive

  2, keyword suggestions uppercase

6, comments:

- Single-line comments // single line comment # single line comment multi-line comments / ** /

7, data types

  int (integer) Integer

  decimal (m, d) decimal precision

  date includes the date, time does not include the minutes and seconds

  datetime include date, it included minutes and seconds  

  timetamp contains period, a time stamp

  varchar (m) 0-65535 m represents a string length

8, we generally create a database of grammar and Methods: Focus

  8,1 create a database

    create database database name;

  8,2 View database

    show databases; this is to look at all of the database

    The new show create database database name;

  8,3 delete database

    drop database database name;

  8,4 query the database name is being used

    select database();

  8,5 convert the database

    use database name;

  The following look at an example:

 

# Create a database 
the CREATE DATABASE day02; 
# database change 
the USE day02; 
# database query 
the SELECT DATABASE (); 
# delete the database 
DROP DATABASE day02; 
# View database 
SHOW DATABASES; 
# see the new database 
SHOW CREATE DATABASE day02;

 

9, create a database table

  9,1 create a database table:

  Syntax: create table table name (

      Column Name Data Type,

      Column Name Data Type

);

  9.2 database table constraints

[] May be omitted on a column of data to be limiting a primary key constraint limits can not be empty of data can not be repeated

The only constraints a null data can not not be repeated

A non-null data constraints can not be empty

  9,3 Table View

    show tables;

  9,4 see table structure

    DESC table name;

  9.5 modify the table name

    raname table the old table to the new table name;

  9,6 modify table structure

    alter table name;

    Syntax: alter table table add Column Name Data Type ();

  9,7 Modify columns constraint length

     modify();

 

# Create a data table 
SHOW TABLE; 
# View table structure 
DESC ruirui; 
# modify the table name 
RENAME TABLE ruirui the TO haohao; 
SHOW TABLE; 
DESC haohao; 
# create a data table 
the CREATE TABLE ruirui ( 
    carid INT, 
    in the Password VARCHAR ( 15 ), 
    `name` VARCHAR ( 10 ), 
    Sex VARCHAR ( 2 ), 
    Age the INT 
); 
# Display 
SHOW tABLES; 
DESC ruirui; 
# table modify 
the RENAME the TO tABLE ruirui huahua; 
DESC huahua;

 

Guess you like

Origin www.cnblogs.com/liurui-bk517/p/10957030.html