mysql基本操作--資料庫表SQL操作
阿新 • • 發佈:2018-11-27
2)MySQL中表的相關操作?(DDL)
a)建立表(語法? create table)
1 create table if not exists pet( 2 id int primary key auto_increment, 3 name varchar(100) not null 4 );
當需要了解具體型別時可以:?具體資料型別
例如:?int
當需要檢視某張表的建立語句時,可以使用
1 show create table pet
當需要顯示錶結構時可以使用:
1 desc pet
b)修改表(語法?alter table);不作為重點,自己瞭解
c)刪除表(語法?drop table)
1 drop table if exists pet;
3)MySQL表中資料的操作?(DML)
1)向表中寫入資料(insert)
1 insert into pet values (null,'A'); 2 insert into pet(id,name) values (null,'B'); 3 insert into pet(name)values('C'); 4 insert into pet(name)values('D'),('E');
2)查詢表中資料(select)
1 select * from pet; 2 select id,name frompet; 3 select id,name from pet where id=10;
分頁查詢:limit 語句的應用(語法參考?select)
1 select * from pet limit 2; --2為row_count(表示要取幾條資料) 2 select * from pet limit 4,2; --4表示offset,2表示 row_count 3 select * from pet limit 2 offset 4;