標籤:
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: \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學習筆記