SQL

建表和添加数据:
drop table if exists student;
create table student(
   sno varchar(20) not null primary key comment'学号',
   sname varchar(20) not null comment'学生姓名',
   ssex varchar(20) not null comment'学生性别',
   sbirthday datetime comment'学生出生年月',
   class varchar(20) comment'学生所在班级'
);
insert into student values 
   ('108','曾华','','1997-09-01','95033'),
   ('105','匡明','','1975-10-02','95031'),
   ('107','王丽','','1976-01-23','95033'),
   ('101','李军','','1976-02-20','95033'),
   ('109','王芳','','1975-02-10','95031'),
   ('103','陆君','','1974-06-03','95031');
View Code

添加数据: 肯定在数据库里面操作

     insert into student (sno,sname,ssex,sbirthday, class) values ('108','曾华','','1997-09-01','95033');
上面的添加语句需要注意的地方
1.字段和值的位置一一对应
2.值的数据类型是字段的数据类型
3.当插入的字段是表中全部字段时 字段可以省略不写 值一一对应
  例如 :insert into student values ('108','曾华','','1997-09-01','95033');

4.不是插入全部的时候字段必须写

  例如 :insert into student(sno,sname) values ('108','曾华');

5.添加多条数据的时候用逗号分隔

 例如 :insert into student values

            ('108','曾华','','1997-09-01','95033'),

            ('105','匡明','','1975-10-02','95031'),

            ('107','王丽','','1976-01-23','95033');

简单查询:

    select * from student

   查一个就是:select sno from student

   查两个(多个)用逗号分隔:select sno,sname from student

字段:

   增:alter  table  表名  add  [column]  字段名  字段类型  字段属性;

   删: alter  table  表名  drop  字段名

   改:alter  table  表名  change  原字段名  新字段名  新字段类型  新字段属性;

mySql中,升序为asc,降序为desc。例如:

升序:select   *  from  表名 order by  表中的字段 asc(mysql中默认是升序排列,可不写)

降序:select   *  from  表名 order by  表中的字段 desc

若要进行同时一个升序,一个降序,则如下:

order by 升序字段 asc,降序字段 desc。

原文地址:https://www.cnblogs.com/xzz123-/p/8907373.html