zoukankan      html  css  js  c++  java
  • mysql学习笔记

    mysql 删除表里面内容,但是不删除表结构

    truncate table dongfang_hk    清除所有数据,主键从1开始
    delete from dongfang_hk 删除所有数据,主键继续增长

    MySQL 添加列,修改列,删除列

    ALTER TABLE:添加,修改,删除表的列,约束等表的定义。

    • 查看列:desc 表名;
    • 修改表名:alter table t_book rename to bbb;
    • 添加列:alter table 表名 add column 列名 varchar(30);
    • 删除列:alter table 表名 drop column 列名;
    • 修改列名MySQL: alter table bbb change nnnnn hh int;
    • 修改列名SQLServer:exec sp_rename't_student.name','nn','column';
    • 修改列名Oracle:lter table bbb rename column nnnnn to hh int;
    • 修改列属性:alter table t_book modify name varchar(22);
    alter table user_info modify user_name varchar(10) after user_id;
    将user_name字段移到user_id后面
    如果想移到最前面:
    alter table user_info modify user_id char(8) first;//将user_id移到最前面!!
    前提 列必须在表中存在

    mysql 错误 SQL Error: 1366: Incorrect string value.

    mysql 错误 SQL Error: 1366: Incorrect string value: xE8xAFxA6xE7xBBx86: for column

    set names utf8   

    若要使excel批量导入mysql,先将excel转成txt格式,再批量导入

    txt载入mysql中

    Load Data InFile 'D:/1.txt' Into Table tablename fields terminated by ',' lines terminated by ' ' // 每个域 ‘,’ 终止 ,每个行 ' '终止

    mysql导出成txt

    select * into outfile 'D:man.txt' from tablename ;

    create table erollment(
    Sno varchar(8) not null,
    Cno varchar(3) not null,
    Tno varchar(6) not null,
    Grade double not null,
    primary key(Sno,Cno,Tno),foreign key (sno) references student(sno),
    foreign key (cno) references courses(cno),foreign key (tno) references teacher(tno)
    );

    可是我的表已经建过了,现在怎么添加外键啊?
    回答
    ALTER TABLE erollment
    add constraint fk_s foreign key (sno) references student(sno),
    constraint fk_c foreign key (cno) references courses(cno),
    constraint fk_t foreign key (tno) references teacher(tno)
    追问
    那个fk_s是什么意思,可以换成其他的吧?
    回答
    可以换、就是约束名字而已、但是不能重复
    
    
  • 相关阅读:
    轻轻松松看懂Spring AOP源码
    centos7安装openjdk8
    使用fiddler做弱网测试
    测试术语-好东西要跟大家一块分享-2
    测试思想-好东西与大家分享-1
    session、token、cookie的区别
    接口测试和功能测试的区别
    常见bug解析-移动端
    接口测试的简介
    软件测试基本理论
  • 原文地址:https://www.cnblogs.com/wincai/p/4257262.html
Copyright © 2011-2022 走看看