MySQL資料庫和表的相關操作

2022-07-17 01:09:13 字數 765 閱讀 4592

show databases;

help create database;

create database 資料庫名 charset utf8;

#檢視資料庫

show databases;

#檢視當前庫

show create database db1;

#檢視所在的庫

select database();

#選擇資料庫

use 資料庫名

#刪除資料庫

drop database 資料庫名;

# 修改資料庫

alter database db1 charset utf8;

create table 表名(

欄位名1 型別[(寬度) 約束條件],

欄位名2 型別[(寬度) 約束條件],

欄位名3 型別[(寬度) 約束條件]

);#注意:

1. 在同一張表中,欄位名是不能相同

2. 寬度和約束條件可選

3. 欄位名和型別是必須的

create database db2 charset utf8;

use db2;

create table a1(

id int,

name varchar(50),

age int(3)

);insert into a1 values

(1,'qwe',18),

(2,'asd',28);

ps:以;作為mysql的結束語

mysql 資料庫和表的操作

庫的建立 create database if not exists book system 庫的刪除 drop database if exists book system 資料庫的修改用alter關鍵字,一般不建議修改 表的建立 create table if not exists book i...

Mysql資料庫相關操作

檢視約束 show indexes from tab name 檢視索引 show index from tab name 檢視資料表的列 show columns from tab name 檢視資料表 show tables 檢視資料庫 show databases 刪除列alter table...

MySQL資料庫操作相關

1 mysql資料庫設定自增序號,刪除表中資料序號錯亂重新排序 alter table tablename drop column id alter table tablename add id mediumint 8 not null primary key auto increment firs...