mysql锿法_MySQL基本用法
常用sql語(yǔ)句
查看數(shù)據(jù)庫(kù): show databases;
創(chuàng)建一個(gè)HA的數(shù)據(jù)庫(kù): create database HA;
查看自己所處的位置: select database();
刪除數(shù)據(jù)庫(kù): drop database 'wg';
創(chuàng)建表:
語(yǔ)法:**create table** 表名 (**字段名** 類型**,** 字段名 類型**,** 字段名 類型**);**
mysql> create table student(id int(20),name char(40),age int);
查看表的相關(guān)信息:
use mysql ;
show tables;
查看表結(jié)構(gòu): desc student;
可以指定默認(rèn)存儲(chǔ)引擎和字符集:
mysql> create table student2(id int(20),name char(40),age int)ENGINE=MyISAM DEFAULT CHARSET=utf8;
刪除表: drop table student2;
修改表名稱:
語(yǔ)法 alter table 表名 rename 新表名
alter table student rename students;
修改表中的字段類型
語(yǔ)法:
alter table 表名 modify 要修改的字段名 要修改的類型
desc student;
alter table students modify column id int(10);
修改表中的字段類型和字段名稱:
語(yǔ)法:**alter table** 表名 change 原字段名 新字段名 新字段類型**;**
alter table students change name stname char(20);
在表中添加字段:
語(yǔ)法: alter table students add sex enum('M','W');#enum是枚舉類型,表示這個(gè)字段中的數(shù)據(jù)只能為F,M,S三個(gè)值中的一個(gè)
在制定位置添加字段
如在第一列添加一個(gè)字段
alter table students add uid int(10) frist;
在age后面添加一個(gè)字段:
alter table students add address char(40) after age;
刪除表中的字段:
alter table students drop address;
插入字段
語(yǔ)法:
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;
所有的都變?yōu)?
update students set id=2;
SQL 基礎(chǔ)條件查詢語(yǔ)句
select name,age from stuendts;
去重復(fù)查詢語(yǔ)句:
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 區(qū)分大小寫查詢
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;
關(guān)于MySQL命令幫助
help show;
help select;
總結(jié)
以上是生活随笔為你收集整理的mysql锿法_MySQL基本用法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 代码谱写传奇,深度揭秘中国开发者现状!
- 下一篇: # hive打不开,提示节点过少,进入安
