zoukankan      html  css  js  c++  java
  • 【mysql】SQL常用指令

     
    常用操作指令
    1. show databases;显示所有的数据库;
    2. use dbName; 使用指定数据库
    3. show tables; 显示所有的数据表;
    4. desc tableName; 查看数据表的字段信息;
    5. show create table tableName; 查询创建表的所有信息;
    6. show create database dbName; 查看数据库创建指令;
    7. show full processlist; 查看所有进程
    8. drop table tableName; 删除表
    9. alter table tableName add constraint 主键(如:PK_TableName) primary key  tableName(主键字段);添加主键约束
    10. alter table tableName add constraint 从表 (如:FK_从表_主表) foreign key 从表(外键字段) references 主表(主键字段) ;添加外键约束
    11. alter table tableName add constraint 唯一约束 (如:uk_t_1) unique(字段名); 添加唯一约束;
    12. alter table tableName drop primary key; 删除主键约束
    13. alter table tableName drop foreign key 外键(区分大小写);删除外键约束
    14. mysqldump -uroot -pXXXX -h19.168.5.2 -P30118 --databases mgmt >/tmp/mgmt.sql: 导出指定数据库

    创建数据库:
    1. create database if not exists `myTestDB`;
     

    创建数据表:
    1. create table if not exists `t_user`(
    2. `userid` int(11) not null auto_increment,
    3. `userName` varchar(32) not null DEFAULT '',
    4. `password` varchar(32) DEFAULT null,
    5. `createTime` timestamp not null DEFAULT CURRENT_TIMESTAMP,
    6. `status` smallint(4) default null,
    7. `lastLoginTime` datetime DEFAULT null,
    8. primary key (`userid`),
    9. UNIQUE key `userName`(`userName`)
    10. )ENGINE=InnoDB auto_increment=3 default CHARSET=utf8;



    插入数据
     
    在指定的列中插入数据
    1. insert into t_user(userName,password,createTime,status,lastLoginTime) values("Tom","12345","2016-12-12 13:45:12",1,"2016-12-12 13:45:12");
    2. insert into t_user(userName,password,createTime,status,lastLoginTime) values("Lily","12345","2016-12-12 14:45:12",1,"2016-12-12 14:45:12");
    3. insert into t_user(userName,password,status,lastLoginTime) values("Jenny","12345",1,"2016-12-12 14:45:12");

     
     
     
  • 相关阅读:
    ireport制作小技巧
    Spring 自动装配 Bean
    Toad创建DBLINKsop
    Spring 读书笔记-----使用Spring容器(一)
    Spring读书笔记-----Spring的Bean之Bean的基本概念
    关于iOS开发中info.plist文件的解读
    iOS常用的第三方库GitHub地址
    NSUserDefault的使用
    论坛收集
    iOS开发的一些奇巧淫技
  • 原文地址:https://www.cnblogs.com/ssslinppp/p/5593330.html
Copyright © 2011-2022 走看看