MySQL中常用的語句(一)

2021-06-28 17:00:23 字數 1037 閱讀 6673

1.查詢資料庫

show databases;

2.切換資料庫

use test(資料庫名稱);

3.查詢**

show tables;

4.建立**

create table [表名](

[自動編號字段] int identity(1,1) primary key,

[欄位1] vachar(20) default \』預設值\』null,

[欄位2] ntext null,

[欄位3] datetime,

[欄位4] money null,

[欄位5] decimal(12.4) default 0,[欄位6] image null

) 5.刪除**

drop table 表名;

6.插入資料

insert into 表名(欄位1,欄位2)values(100,」zhongguo」)

7.刪除資料

delete from 表名 where 欄位名》condition

8.清空**資料

delete from 表名;

9.更新資料

update 表名 set 欄位1=值1,欄位2=值2 where 欄位1>condition

若不加where則更新表中所有的字段值,若加where則只更新符合條件的記錄

10.新增字段

alter table 表名 add 欄位名 varchar(10) null;

11.刪除字段

alter table 表名 drop column 欄位名;

12.修改字段

alter table 表名modifycolumn 欄位名 varchar(10) null;

13.重新命名表

rename table 老表名 to 新錶名;

14.新建約束

alter table 表名 add constraint 約束名 check(約束字段

mysql中常用的語句 mysql中常用的語句整理

mysql中常用的語句 1 建立帶自增長的主鍵的表 drop table if exists user login create table user login user id int unsigned not null auto increment,user name varchar 50 de...

MySQL中常用的語句(二)

15.刪除約束 alter table 表名 drop constraint 約束名 16.新建預設值 alter table 表名 add constraint 預設值名 default null for 欄位名 17.刪除預設值 alter table 表名 drop constraint 預設...

MySQL中常用的SQL語句

create database 庫名 charset 指定字符集 其中有兩個常用字符集分別是utf8和utf8mb4,utf8mb4支援標稱符號的儲存 刪除乙個庫 drop database 庫名 修改庫的字符集 alter database 庫名 charset 要指定的新的字符集 檢視乙個資料庫...