mysql做筆記 mysql學習筆記

2021-10-19 19:09:05 字數 1751 閱讀 6019

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: \xe8\xaf\xa6\xe7\xbb\x86: 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 '\n' // 每個域 『,』 終止 ,每個行 '\n'終止

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是什麼意思,可以換成其他的吧?

回答可以換、就是約束名字而已、但是不能重複

mysql做筆記 mysql筆記

當key cache miss rate key reads key read requests 100 大於1 時需要增加 key buffer size show global status like key read 對於myisam 需要注意table cache的設定 當這個不夠用時mys...

mysql學習筆記 51 mysql學習筆記

初學mysql時整理,隨時更新 資料操作 增 insert into 表名 字段列表 values 值列表 值列表 如果要插入的值列表包含所有字段並且順序一致,則可以省略字段列表。可同時插入多條資料記錄!replace 與 insert 完全一樣,可互換。insert into 表名 set 欄位名...

mysql學習筆記 51 Mysql 學習筆記

一.首先進入mysql mysql u root p新增使用者許可權設定 grant all privileges on to jerry localhost identified by aa1234567 只允許本機訪問 grant all privileges on to jerry 10.80...