mysql增查删改

mysql> use test
Database changed
mysql> create table class (
    -> id int primary key auto_increment,
    -> sname varchar(10) not null default '',
    -> gender char(1) not null default '',
    -> company varchar(20) not null default '',
    -> salary decimal(6,2) not null default 0.00,
    -> fanbu smallint not null default 0
    -> )engine myisam charset utf8;
Query OK, 0 rows affected (0.11 sec)

mysql> desc class;
+---------+--------------+------+-----+---------+----------------+
| Field   | Type         | Null | Key | Default | Extra          |
+---------+--------------+------+-----+---------+----------------+
| id      | int(11)      | NO   | PRI | NULL    | auto_increment |
| sname   | varchar(10)  | NO   |     |         |                |
| gender  | char(1)      | NO   |     |         |                |
| company | varchar(20)  | NO   |     |         |                |
| salary  | decimal(6,2) | NO   |     | 0.00    |                |
| fanbu   | smallint(6)  | NO   |     | 0       |                |
+---------+--------------+------+-----+---------+----------------+
6 rows in set (0.02 sec)

mysql> insert into class
    -> (id,sname,gender,company,salary,fanbu)
    -> values
    -> (1,'张三','男','百度',8889.23,250);
Query OK, 1 row affected (0.05 sec)

mysql> insert into class
    -> (sname,gender,salary)
    -> values
    -> ('科比','男',9000);
Query OK, 1 row affected (0.00 sec)

mysql> select * from class;
+----+--------+--------+---------+---------+-------+
| id | sname  | gender | company | salary  | fanbu |
+----+--------+--------+---------+---------+-------+
|  1 | 张三   | 男     | 百度    | 8889.23 |   250 |
|  2 | 科比   | 男     |         | 9000.00 |     0 |
+----+--------+--------+---------+---------+-------+
2 rows in set (0.00 sec)

mysql> insert into class
    -> values
    -> (3,'李四','女','新浪',5888.90,125);
Query OK, 1 row affected (0.00 sec)

mysql> insert into class
    -> values
    -> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 2
mysql> insert into class
    -> (sname,company,salary)
    -> values
    -> ('刘备','皇室',1000.00),
    -> ('孙策','江东集团',8000.00),
    -> ('曹操','魏国',5000.00);
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> select * from class;
+----+--------+--------+--------------+---------+-------+
| id | sname  | gender | company      | salary  | fanbu |
+----+--------+--------+--------------+---------+-------+
|  1 | 张三   | 男     | 百度         | 8889.23 |   250 |
|  2 | 科比   | 男     |              | 9000.00 |     0 |
|  3 | 李四   | 女     | 新浪         | 5888.90 |   125 |
|  4 | 刘备   |        | 皇室         | 1000.00 |     0 |
|  5 | 孙策   |        | 江东集团     | 8000.00 |     0 |
|  6 | 曹操   |        | 魏国         | 5000.00 |     0 |
+----+--------+--------+--------------+---------+-------+
6 rows in set (0.00 sec)

mysql> update class set gender='男' where id=4;
Query OK, 1 row affected (0.03 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from class;
+----+--------+--------+--------------+---------+-------+
| id | sname  | gender | company      | salary  | fanbu |
+----+--------+--------+--------------+---------+-------+
|  1 | 张三   | 男     | 百度         | 8889.23 |   250 |
|  2 | 科比   | 男     |              | 9000.00 |     0 |
|  3 | 李四   | 女     | 新浪         | 5888.90 |   125 |
|  4 | 刘备   | 男     | 皇室         | 1000.00 |     0 |
|  5 | 孙策   |        | 江东集团     | 8000.00 |     0 |
|  6 | 曹操   |        | 魏国         | 5000.00 |     0 |
+----+--------+--------+--------------+---------+-------+
6 rows in set (0.00 sec)

mysql> select * from class\G
*************************** 1. row ***************************
     id: 1
  sname: 张三
 gender: 男
company: 百度
 salary: 8889.23
  fanbu: 250
*************************** 2. row ***************************
     id: 2
  sname: 科比
 gender: 男
company:
 salary: 9000.00
  fanbu: 0
*************************** 3. row ***************************
     id: 3
  sname: 李四
 gender: 女
company: 新浪
 salary: 5888.90
  fanbu: 125
*************************** 4. row ***************************
     id: 4
  sname: 刘备
 gender: 男
company: 皇室
 salary: 1000.00
  fanbu: 0
*************************** 5. row ***************************
     id: 5
  sname: 孙策
 gender:
company: 江东集团
 salary: 8000.00
  fanbu: 0
*************************** 6. row ***************************
     id: 6
  sname: 曹操
 gender:
company: 魏国
 salary: 5000.00
  fanbu: 0
6 rows in set (0.00 sec)

 

#建立文件,并把操作mysql表的内容全部显示
tee F:\1230.sql
#学生表
create table class (
id int primary key auto_increment,
sname varchar(10) not null default '',
gender char(1) not null default '',
company varchar(20) not null default '',
salary decimal(6,2) not null default 0.00,
fanbu smallint not null default 0
)engine myisam charset utf8;

#查看表的结构
desc class;
#增加一条信息
insert into class
(id,sname,gender,company,salary,fanbu)
values
(1,'张三','男','百度',8889.23,250);

#特殊情况
insert into class
(sname,gender,salary)
values
('科比','男',9000);

#插入所有列
insert into class
values
(3,'李四','女','新浪',5888.90,125);

#插入多列
insert into class
(sname,company,salary)
values
('刘备','皇室',1000.00),
('孙策','江东集团',8000.00),
('曹操','魏国',5000.00);

#修改
update class set gender='男' where id=4;

#全部改
update class set fanbu=100 where 1;
#where 1 ,1 表示真,1恒为真

#删除
delete from class where id=1;

#查询
select * from class;
时间: 2024-09-17 15:35:43

mysql增查删改的相关文章

node.js操作mysql(增删改查)_node.js

最近这段时间研究Node感觉不错,自己做了一个增删改查,虽然有些简陋,但是思想是想通的,其实所有项目都是增删改查,有助于初学者快速掌握Node  首先 本实例展示的是基于Node+Express+node-mysql快速搭建的一套增删改查,视图模板是jade,基本上都是现在能用的到的技术,市面上的实例也特别少,有用的又不新,所以自己写一个  基本工作 首先我们准备一些基本的,因为我是用mysql麻烦可以自己装一下mysql,去官网可以下各种操作系统的安装包. 实例就一张表,下面是这张表的建表语句

PHP MySql增删改查的简单实例_php实例

mysql_connect()连接数据库 mysql_select_db选择数据库 mysql_fetch_assoc()获取结果集 mysql_query()执行sql语句 实例如下: <?php $con=@mysql_connect('localhost','root','root');//连接数据库 mysql_select_db('test',$con);//选择数据库 $userInfo=mysql_query("select * from user",$con);/

PHP MySql增删改查的简单实例

mysql_connect()连接数据库 mysql_select_db选择数据库 mysql_fetch_assoc()获取结果集 mysql_query()执行sql语句 实例如下: <?php $con=@mysql_connect('localhost','root','root');//连接数据库 mysql_select_db('test',$con);//选择数据库 $userInfo=mysql_query("select * from user",$con);/

EF里单个实体的增查改删以及主从表关联数据的各种增删改查

原文:EF里单个实体的增查改删以及主从表关联数据的各种增删改查 本文目录 EF对单个实体的增查改删 增加单个实体 查询单个实体 修改单个实体 删除单个实体 EF里主从表关联数据的各种增删改查 增加(增加从表数据.增加主从表数据) 查询(查询导航属性为集合.查询导航属性为单个对象) 修改(修改从表的外键) 删除(删除主从表关系.删除主表数据.删除主从表数据.修改从表数据外键) 补充内容 SaveChanges方法提交多次操作 DbSet.Add方法返回当前实体 源码和系列文章导航 注:本章节多次演

mysql 增删改查基本语句

增: insert insert into 表名(字段1,字段2,字段3......字段N) values(值1,值2,值3): 如果不申明插入那些字段,则默认所有字段. 在插入时注意,往哪个表增加,增哪个字段,每个字段各有什么值. 删: delete delete from 表名 where 表达式: 删除时注意 删除哪张表数据,删除哪些行. 改: update update 表名 set  字段1=值1,字段2=值2  .......字段N=值N where  表达式: 修改时注意 修改哪张

mysql增删改

要对数据表进行增删改查,我们先建立两张测试表: 1. 部门表 CREATE TABLE `tb_dept` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `name` VARCHAR(15) DEFAULT NULL, `description` VARCHAR(100) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=INNODB DEFAULT CHARSET=utf8; 2. 员工表 DROP TABLE IF EXIS

MySQL动态添删改列字段

好吧,我承认是自己项目中重大的失误,在这个项目试运行期间,对数据库字段的长度以及字段的值进行修改了两次,为了不影响里边已经存在的数据,那么我只能是再次寻找一种方法去动态增删改列字段 动态增加列字段 ? 1 alter table TableName drop column field_id; 动态删除列字段 ? 1 alert TABLE table_name change old_field_name new_field_name field_type; 动态修改列字段 ? 1 alert T

MySQL动态添删改列字段命令

MySQL如何动态添删改列字段呢,SQL如下: 动态增加列字段: ALERT TABLE table1 add transactor varchar(10) not Null; 动态删除列字段: ALERT TABLE TableName drop column field_id; 动态修改列字段: ALERT TABLE table_name change old_field_name  new_field_name field_type; 动态修改表结构 ALERT TABLE table_

Mariadb/MySQL 增删查改 数据库操作 建表 建数据库

首先需要安装好 MySQL/Mariadb 的服务端和客户端,并且能连接到服务端 命令中的大写字母是 SQL 的关键字,小写字母是自己的相关属性和数据 0X00 连接到数据库 使用mysql连接到127.0.0.1并用root用户登陆,密码等待输入 mysql -h 127.0.0.1 -u root -p 0X01 创建数据库 创建一个名为school的数据库 CREATE DATABASE school; 0X02 建立一个表 建立一个名为 student 的表 索引: 10 个字符长度的