mysql 資料庫表的操作

2021-08-09 02:43:48 字數 1286 閱讀 5722

show databases  //  顯示資料庫

use databases //進入資料庫

show tables //顯示表

describe mytable //顯示表結構

create

database mydatabase;

use mydatabase;

create

table mytable(name varchar(20),gender varchar(1));

insert into mytable values("star","senior")
使用文字方式插入資料:

mysql> load data local infile "mytable.txt" into table pet;
drop database drop_database;   //刪除乙個已經確定存在的資料庫

alter table 表名 engine=儲存引擎名; //修改表的儲存引擎

alter table 表名 drop 屬性名; //刪除字段

alter table 舊表名 rename to 新錶名; //修改表名

alter table 表名 modify 屬性名 資料型別; //修改字段資料型別

alter table 表名 change 舊屬性名 新屬性名 新資料型別; //修改欄位名

alter table 表名 drop foreing key 外來鍵別名; //刪除子表外來鍵約束

#增加表字段

alter table example add phone vacgar(20); //增加無約束的字段

alter table example add age int(4) not null; //增加萬增約束的字段

alter table example add num int(8) primary key first; //表的第乙個位置增加字段

alter table example add address varchar(30) not null after phone; //表的指定位置之後增加字段

alter table example modify name varchar(20) first; //把字段修改到第一位

alter table example modify num int(8) ater phone;//把字段修改到指定字段之後

資料庫 MySQL表的操作

1.建立表 create table table name 欄位名稱 字段型別,欄位名稱 字段型別,欄位名稱 字段型別,character set 字符集 collate 校驗規則 engine 儲存引擎 針對資料表而非資料庫 character set 字符集 collate 校驗規則 engin...

MYSQL 資料庫表的操作

show tables 2,create table 表名 欄位名1 資料型別 約束,欄位名2 資料型別 約束,欄位名n 資料型別 約束 engine mysiam innodb charset utf8 3.刪除表 drop table 表1,表2,表3 更改資料 update 表名 set 欄位...

資料庫(mysql)表的操作

1 建立表,使用create 語法 create table 表名 列名1 資料型別 約束 列名1 資料型別 約束 列名1 資料型別 約束 建立表,並且給id欄位加入加入主鍵 約束 唯一且絕對不可以為空 唯一標識表中一行記錄 注意 建立表的時候一定要加入主鍵 primary key create t...