MySQL的儲存引擎與表的建立,鍵的定義,等等

來源:互聯網
上載者:User

標籤:主鍵   預設值   儲存引擎   外鍵   唯一性限制式   自增屬性   

--select * from products--select prod_name from products/*limit 7 offset 2 */--從第二行往下取7行資料,若不足7行,則取實際包含的行數 --limit 2,7--等同

手抖把寨板弄翻過來了,嚇得筆記本硬碟離線,重啟後只剩下上面這點練習了,下面是今天練習Mysql關於表的

select * from ordersorder by 2,3show enginesshow variables like ‘%innodb%‘show variables like ‘%storage_engine%‘ --查看mysql當前預設的儲存引擎:show table status from test where name =‘test‘--查看test庫的test表的儲存引擎資訊----建立表,並指定其儲存引擎為InnodbUSE TESTcreate table test_engine (id int not null auto_increment, temp varchar(10),--varchar類型需要指定長度,否則會報錯無法建立表 primary key (id) ) engine = innodb--更改表的儲存引擎alter table engine= myisam--報錯,不知道為何--小練習1create table example0(id int not null auto_increment primary key,  name varchar(20),  sex  boolean           --等同與tinyint(1)  )--小練習2--組合主鍵use testcreate table sc(sNo int not null,cNo int not null,/*突然想起了select 2 from table的問題了,實驗一下use world;select 2 from world.city --結果為選出一列n行的2,n為city表的行數*/grade int default ‘0‘,--不能少逗號,即使下面沒有屬性聲明只有主鍵定義。。。primary key (sNo,cNo))use test;create table sc(sNo int ,--這裡之前有not null 然後建立的時候就一直出錯cNo int ,--同上(上面一個例子是不是也是這個原因?不明白為啥,實驗一下)grade int default ‘0‘,primary key (sNo,cNo))create table example1(id int not null auto_increment primary key,  name varchar(20),--果然不加(20)就會報錯,為什嗎?  sex  boolean  )/*子表的外鍵必須是父表的主鍵,且資料類型需一致*/create table example3(id int primary key, stu_id int, course_id int, constraint c_fk foreign key(stu_id,course_id) references example2(stu_id,course_id) --報錯,無法建立example3表。查詢書籍,可能是被依賴的example2表及其屬性不存在 --先回來建立表example2 )create table example2(stu_id int,  course_id int,  grade float,  primary key(stu_id,course_id) )create table example3(id int primary key, stu_id int, course_id int, constraint c_fk foreign key(stu_id,course_id) references example2(stu_id,course_id)  ) --Command(s) completed successfully./*欄位唯一性限制式,欄位自增屬性,欄位預設值(之前的例子中,int預設值0不加‘’報錯,再預先實驗一下)*/ --把小練習2複製過來,以後的例子都要編號,方便調用。。。  create table sc1(sNo int not null,cNo int not null,grade int default 0,primary key (sNo,cNo))--Command(s) completed successfully.看來是我自己弄錯了  --小練習3 create table example7(id int primary key auto_increment,   stu_id int unique,   name varchar(20) not null,   English varchar(20) default ‘zero‘,   Math float default 0,   Computer Float default 0   ) --Command(s) completed successfully.關於表的練習結束

   

 

  

 


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.