登录  /  注册
博主信息
博文 49
粉丝 0
评论 0
访问量 47635
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
常用数据库操作指令
lus菜
原创
2228人浏览过

数据库操作指令:

样式代码:

  1. // 创建phpedu数据库
  2. create database phpedu collate utf8mb4_unicode_ci;
  3. // 选择默认数据库
  4. use phpedu;
  5. select database();
  6. // 删除phpedu库
  7. drop database phpedu;
  8. // 查看建库语句
  9. show create database phpedu;
  10. // 创建数据表 sjbcz
  11. create table sjbcz (
  12. sid int unsigned auto_increment not null primary key comment 'ID',
  13. name varchar(20) not null comment '姓名',
  14. gender enum('man','girl') not null comment '性别',
  15. email varchar(150) not null comment '邮箱',
  16. birthday date not null comment '出生日',
  17. create_at timestamp not null default current_timestamp comment '创建时间',
  18. update_at timestamp not null default current_timestamp on update current_timestamp comment '更新时间'
  19. ) engine = innodb auto_increment=1 collate = utf8mb4_unicode_ci;
  20. // 删除数据表
  21. drop table sjbcz;
  22. // 查看建表语句
  23. show create table sjbcz;
  24. // 查看表结构
  25. desc sjbcz;
  26. // 查看库中有哪些表?
  27. show tables;
  28. // 修改表
  29. // 增加字段
  30. alter table sjbcz add salary int unsigned not null default 2000 after gender;
  31. // 更新字段定义
  32. alter table sjbcz change salary salary float unsigned not null default 3000 after gender;
  33. // 删除字段
  34. alter table sjbcz drop test;
  35. // 插入数据
  36. insert sjbcz (name, gender, salary, email, birthday)
  37. values('小明同学', 'man', 8800, 'w123@php.cn', '2000-1-2'),
  38. ('小张同学', 'girl', 348800, 'w989@ydsq.cn', '2001-2-23');
  39. // 子查询式插入/数据复制插入
  40. insert sjbcz (name,gender, salary, email,birthday)
  41. (select name,gender, salary, email,birthday from sjbcz);

数据表效果预览:

数据效果预览:

本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学