mysql锿法_MySQL基本用法
常用sql語句
查看數據庫: show databases;
創建一個HA的數據庫: create database HA;
查看自己所處的位置: select database();
刪除數據庫: drop database 'wg';
創建表:
語法:**create table** 表名 (**字段名** 類型**,** 字段名 類型**,** 字段名 類型**);**
mysql> create table student(id int(20),name char(40),age int);
查看表的相關信息:
use mysql ;
show tables;
查看表結構: desc student;
可以指定默認存儲引擎和字符集:
mysql> create table student2(id int(20),name char(40),age int)ENGINE=MyISAM DEFAULT CHARSET=utf8;
刪除表: drop table student2;
修改表名稱:
語法 alter table 表名 rename 新表名
alter table student rename students;
修改表中的字段類型
語法:
alter table 表名 modify 要修改的字段名 要修改的類型
desc student;
alter table students modify column id int(10);
修改表中的字段類型和字段名稱:
語法:**alter table** 表名 change 原字段名 新字段名 新字段類型**;**
alter table students change name stname char(20);
在表中添加字段:
語法: alter table students add sex enum('M','W');#enum是枚舉類型,表示這個字段中的數據只能為F,M,S三個值中的一個
在制定位置添加字段
如在第一列添加一個字段
alter table students add uid int(10) frist;
在age后面添加一個字段:
alter table students add address char(40) after age;
刪除表中的字段:
alter table students drop address;
插入字段
語法:
insert into 表名 values ( 字段值1,字段值2,字段值3);
insert into student values(1,'zhangs',21);
查詢表中的記錄
select * from student ;
select id,name from student;
刪除id 為3的行:
delete from students where id=3;
刪除age為空的行;
delete from students where age is null;
更新記錄:
update students set sex='M' where id=2;
所有的都變為2
update students set id=2;
SQL 基礎條件查詢語句
select name,age from stuendts;
去重復查詢語句:
select distinct name,age from students;
select distinct id,name,age from students where id=3;
select id,name from students where id >3 and age >25;
select id,name from students where id >3 or age >25;
mysql 區分大小寫查詢
select name from studnets where name='jk';
select * from students where binary name ='jk';
mysql 查詢排序:
select distinct id from students order by id;
select distinct id from students order by id desc;
關于MySQL命令幫助
help show;
help select;
總結
以上是生活随笔為你收集整理的mysql锿法_MySQL基本用法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 代码谱写传奇,深度揭秘中国开发者现状!
- 下一篇: 如何把数据库从sql变成mysql_如何