標籤:主鍵 預設值 儲存引擎 外鍵 唯一性限制式 自增屬性
--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的儲存引擎與表的建立,鍵的定義,等等