mysql单表修改

目录

 1.创建表

2.插入数据    

 3.修改表数据   


作业:
    1.创建表:
    创建员工表employee,字段如下:
    id(员工编号),name(员工名字),gender(员工性别),salary(员工薪资)
mysql> create table employee (
    -> id int not null comment'员工编号',
    -> name varchar(20)  not null comment'员工名字',
    -> gender char(1)  not null comment'员工性别',
    -> salary int 
    -> );
2.插入数据
    1,‘张三’,‘男’,2000
    2,‘李四’,‘男’,1000
    3,‘王五’,‘女’,4000
mysql> insert  into employee values (1,'zhangsan','男',2000);


如出现此报错:ERROR 1366 (HY000): Incorrect string value: '\xE7\x94\xB7' for column 'gender' at row 1
字符集问题!!!!!

解决方法:修改字符集
 

#查看建表字符集
mysql> show create table employee;
#CHARSET=latin1  
mysql>ALTER TABLE employee CONVERT TO CHARACTER SET utf8;

  

mysql> insert  into employee values (1,'zhangsan','nan',2000);
ERROR 1406 (22001): Data too long for column 'gender' at row 1
mysql> insert  into employee values (1,'张三','男',2000);
Query OK, 1 row affected (0.00 sec)

mysql> insert  into employee values (2,'李四','男',1000);
Query OK, 1 row affected (0.00 sec)

mysql> insert  into employee values (3,'王五','女',4000);
Query OK, 1 row affected (0.00 sec)
 3.修改表数据
    3.1 将所有员工薪水修改为5000元
mysql> update employee set salary=5000;                


    3.2将姓名为张三的员工薪水修改为3000元

mysql> update employee set salary=4000 where name='张三';


    3.3将姓名为李四的员工薪水修改为4000元,gener改为女

update employee set salary=3000,gender='女' where name='李四';


    3.4 将王五的薪水在原有基础上增加1000元

mysql> update employee set salary=salary+1000 where name='王五';

你可能感兴趣的:(mysql,数据库)