006- database of "CRUD"

First, by

Inserting a student, all fields of information, with the order table values ​​corresponding to the fields

insert into students values('亚瑟',20)

Inserting a student, the name of setting only, and the order of the fields corresponding to the value given by

insert into students(name) values('鲁班')
insert into students(age) values(30)
insert into students(age,name) values(30,'亚瑟2')

When the table has auto_increment fields, when adding data using default or null to zero or placeholder

Students. INTO values INSERT (0, ' Old Master 3 ' , 20);

Insert multiple data

INSERT INTO Students. values (0, ' Old Master. 3 ' , 20 is ); 
INSERT INTO Students. values (0, ' Old Master. 4 ' , 20 is ); 
INSERT INTO Students. values (0, ' Old Master. 5 ' , 20 is ); 

INSERT INTO Students. values ( 0, ' the old lady 3 ' , 20), (0, ' the old lady 4 ' , 20), (0, ' the old lady. 5 ' , 20 ) 

INSERT INTO Students. (ID, name) values (0, ' the old lady 3 ' ), ( 0, ' the old lady 4 ' ), (0, ' the old lady 5 ')

Second, delete

Simply delete

Format: the Delete from table where conditions

delete from students where name='亚瑟3'

Tombstone

1, a field is added, whether the identification data is deleted is_delete
  default setting is 0, the representative data is not deleted
  represents deleted, the default value is 0

2、update students set is_delete=0

3, delete a data, but this data is changed to 1 is_delete

  update students set is_delete=1 where name='老夫子6'

4, the query for all students, the students do not show deleted

    select * from students where is_delete=0

update students set is_delete=0
update students set is_delete=1 where id=1
select * from students where is_delete=0

Third, reform

Modify data: five students set id name is Di Renjie, aged 20

update students set name='狄仁杰',age=20 where id=5

Update Data: Set one of the student's age plus 3 years old

update students set age=age+3 where name='亚瑟3'

To alias the field:

select name as the name, age as the age, hometown as home from Students the WHERE name = ' Wang Zhaojun ' 
the SELECT name name, age Age, hometown home from Students the WHERE name = ' Wang Zhaojun '

 

Guess you like

Origin www.cnblogs.com/qiuniao/p/11964743.html