mysql學習筆記

來源:互聯網
上載者:User

標籤:

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學習筆記

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.