Introduction to Databases

database DATABASE

 

MySql oracle port 3306

Oracle port 1521

Sqlserver port 1433

 

divided into

DDL defines the class statement such as building a table library and changing the table structure

DML operation class statement Data addition, deletion, modification, search, etc.

DCL Control Statement Privilege Control Transaction Control

 

DDL:

create database create database database name

delete library drop database library name

switch database use library name 

create table create table table name (

        column name column type,

        column name column type

       )

           create  table  myuser(

       hat int

       uname VARCHAR(20),

       sex  varchar(2)

        );

drop table drop table myuser;

Modify the table structure alter table myuser ADD age int;

 

DML manipulation data

 add insert into table(column,column) values(value,value);

   insert into myuser(uid,uname,sex,age) values(1,'小强','男',22);

delete delete from table where condition  

   delete  from  myuser where uid>=3;

   delete from   myuser where  uname='张三丰'   or uid=2  ;

change

  update table set column=value, column=value where condition

update  myuser  set sex='女' ,age=18  where uid=3 and uname='张三丰'

check

 select column,column,column from table where condition

       * represents all columns

 select * from myuser where  age>18;

 

 

column type

     Numerical

        tinyint   smallint   int 整数   bigint

         float   double     

     character type

        char 0~255 fixed-length characters 

            In name char(10) ______ exchange space for time          

            Insufficient right-hand padding spaces will be automatically removed when querying

        varchar 0~65535 bytes If it is utf-8, a Chinese character is processed by 3 bytes, 21844 Chinese characters

            Name varchar(9) occupies three bytes and uses time for space   

        text 65535 characters

        longtext  4G  

     date type

        datetime date time stores the year, month and day

        timestamp date and time stored in seconds

     Large field type to store some file xml text information

       blob  65535 byte

       longlob 4g

 

check sentence

where condition

l column=value and and or or > < >= <= != not equal to <> not equal to >< not true

l column in (value, value, value) The value of the column is one of the brackets   

select * from myuser  where  age in (18,20,23,500)

l column between value and value 1 column value >= value and <= value 1

select * from myuser  where age BETWEEN 19 and  499;

l Column like fuzzy query % any character _ any character

 select * from myuser where uname like '%张%'

l Sort order by column asc ascending order (default) desc descending order is placed at the end of sql

select * from myuser  order by  uid  desc ,age asc; 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325894922&siteId=291194637