資料庫操作語句

2022-08-19 19:18:06 字數 1521 閱讀 7311

1、建立資料庫

命令:create database 《資料庫名》

例如:建立乙個名為test的資料庫

drop database life if exists test;

create database life character set utf8;

use life;

set names 'gbk';

2、顯示所有的資料庫

命令:show databases

3、刪除資料庫

命令:drop database 《資料庫名》

例如:刪除名為 test的資料庫

mysql> drop database test;

6、檢視當前使用的資料庫

mysql> select database();

7、建立表

create table course(id integer primary key autoincrement,week text not null,teacher int default 0,name varchar(64))"default charset=utf8;;

7.1在表中新增字段

alter table stuinfo add column msg text null

7.2在表中刪除字段

alter table stuinfo drop column msg;

8、刪除表

drop table student;

9、當前資料庫包含的表資訊:

mysql> show tables;

10、mysql的退出命令為quit或者是exit。

四、表的增刪查改

1、插入資料

insert into stuinfo (id,password,name) values(?,?,?)

如果表stuinfo只有3列,則可以簡單點

insert into stuinfo values(?,?,?)

五、表的查詢

1、查詢從第m條開始的n條記錄

select * from something limit 100,5 顯示something從第100條開始的5條的資料

2、查詢後排序

例1:sql="select * from tb_info order by  需要排序的列名 asc"  ---公升序排序

例2:sql="select * from tb_info order by 需要排序的列名 desc" ---降序排序

3、刪除資料

delete from tb_notice where 條件;

六、表的更改

update person set address = 'zhongshan 23', city = 'nanjing'

where lastname = 'wilson'

更改mysql 表字段為unique

用alter命令,**如下:

alter table user add unique key(`name`)

done!

資料庫操作語句

mysql分頁limit用法 limit後的第乙個引數是輸出記錄的初始位置,第二個引數偏移量。如 select from tables limit 10,3 返回的就是11到13,3條資料。如果只給定乙個引數,它表示返回最大的記錄行數目 select from table limit 5 檢索前 5...

資料庫操作語句

1 檢視當前資料庫版本資訊 select from product component version select from v version 2 授權與取消 grant 許可權 如sysdba to 使用者名稱 revoke 許可權 如sysdba from 使用者名稱 3 檢視資料庫中哪些使...

ASP 資料庫操作語句

1.連線資料庫 2.插入資料 3.更新資料 4.刪除資料 4.刪除資料 刪除資料 set rsdelete server.createobject adodb.connection rsdelete.open mm conn string 注意,輸入為數字不能加單引號 sql delete from...