MySQL数据库 基本操作语句
操作MySQL數據庫
1、創建數據庫
create database 數據庫名;
2、查看數據庫
show databases;
3、選擇指定數據庫
use 數據庫名;
4、刪除數據庫
drop database 數據庫名;
注:自動刪除MySQL安裝目錄中的“C:/AppServ/MySQL/data”文件夾。
?
操作MySQL數據
1、添加表數據
語法1:insert into 表名 values(值1,值2,...)(自增長的列應寫null)
語法2:insert into 表名(字段1,字段2,...) values (值1,值2,...)
語法3:insert into 表名 set 字段1=值1,字段2=值2,...
2、更新表數據
update 表名 set 字段1=值1 where 查詢條件
若無查詢條件,表中所有數據行都會被修改。
3、刪除表數據
delete from 表名 where 查詢條件
若無查詢條件,表中所有數據行都會被刪除。
4、查詢表數據
select * from 表名;
5、限制查詢記錄數
select * from 表名 limit[start] length
start:表示從第幾行記錄開始輸出,0表示第1行
?
?
操作MySQL數據表
1、創建表
create table 表名?(column_name column_type not null,...)
| 屬性 | 說明 | 屬性 | 說明 |
| column_name | 字段名 | Primary key | 該列是否為主碼 |
| column_type | 字段類型 | AUTO_INCREMNT | 該列是否自動編號 |
| Not null | null | 該列是否允許為空 | ? | ? |
?
?
?
?
?
創建數據表后,“C:\AppServ\MySQL\data\數據庫名\”中自動創建對應表文件(“表名.frm”,“表名.MYD”,“表名.MYI”)
2、查看數據庫中的表
show tables;
3、查看數據庫中所有的表
show tables;(前提是使用use database 數據庫;)
4、查看數據表結構
describe 表名;
5、修改數據表結構
alter table 表名
add [column] create_definition [first | after column_name] //添加新字段
add primary key (index_col_name,...) //添加主碼名稱
alter [column] col_name {set default literal |rop default} //修改字段名稱
change?[column] old_col_name create_definition //修改字段名及類型
modify?[column] create_definition //修改字段類型
drop?[column] col_name //刪除字段
drop primary key //刪除主碼
rename [as] new_tablename //更改表名
eg:alter table Admin_Info
drop A_Pwd,
rename as Admin_Info2;
6、刪除指定數據表
drop table 表名;
?
轉載于:https://www.cnblogs.com/wjw1014/p/8684519.html
總結
以上是生活随笔為你收集整理的MySQL数据库 基本操作语句的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 火狐插件youdao word capt
- 下一篇: ftp服务器在linux中安装