mySQL笔记(1)
1.show databases; ? ? 顯示所有數(shù)據(jù)庫
2.create database 數(shù)據(jù)庫名 ?[其他選項]; ? ? 新建數(shù)據(jù)庫
? ? 例:create database example_db ?character set gbk; ?創(chuàng)建了一個名為example_db的數(shù)據(jù)庫,并將數(shù)據(jù)庫字符編碼指定為gbk,便于在命令提示符下顯示中文。
3.use 數(shù)據(jù)庫名; ?選擇要用的數(shù)據(jù)庫
4.show tables; ? ? 顯示已選擇的數(shù)據(jù)庫中的所有表
5.create table 表名(列名 ?數(shù)據(jù)類型,........); ? ?創(chuàng)建表
? ? 例:create table students(
? ? ? ? ? ? ? ? ? id ? int ? ?not null ? ?primary key,
? ? ? ? ? ? ? ? ?name ?char(8) ?not null,
? ? ? ? ? ? ? ? ?password ?varchar(20)?
); ? ? ? ? ? ? ?
6.alter table 表名 ?add ?要插入的列名稱 ? 數(shù)據(jù)格式 ?[after 插入位置];; ? ? ? ? ? ?在建好的表中插入一列
? ? ?例:alter table students add tel varchar(13) ?after password;
7.alter table 表名 ?drop column ?要刪除的列名稱; ? ? ? ? ? ? ?在建好的表中刪除一列
? ? ?例:alter table students drop column tel;
8.insert 【into】 表名(列名1,列名2,......)values(列值1,列值2,......); ? ? ?在表中插入數(shù)據(jù)
? ? 例:insert into students(id,name) values(01,'李明');
? ? ? ? ? ?或 insert students values(01,'李明','qwe123');
9.select * from 表名 where 查詢條件; ? ? ? 查詢滿足條件的表中的所有信息
? ?select 列名 from 表名 where 查詢條件; ? ? ? 查詢滿足條件的所有列信息
? ? 例:select id,name ?from students;
10.update 表名 set 列名=新值 where ?更新條件; ?修改表中的數(shù)據(jù)
? ? 例:update students set id=id+1 where name='李明';
11.delete from 表名 ?where 刪除條件;
? ? 例:delete ?from ?students ?where name='李明';
12.drop table 表名; ? ? 刪除整張表
13.drop database 數(shù)據(jù)庫名; ? ? 刪除整個數(shù)據(jù)庫
14.alter table 表名 change 列名 列新名稱 新數(shù)據(jù)類型; ? ? 修改列
? ? 例:alter table students change password password char(10) not null;
15.alter table 表名 rename 新表名; ? ? ? 重命名表
?
注:參考http://www.cnblogs.com/mr-wid/archive/2013/05/09/3068229.html
?
轉(zhuǎn)載于:https://www.cnblogs.com/lifan94/p/4675112.html
總結(jié)
以上是生活随笔為你收集整理的mySQL笔记(1)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Corn Fields(POJ 3254
- 下一篇: 求一个天冷求暖床个性签名