> 데이터 베이스 > MySQL 튜토리얼 > MySQL复习笔记I_MySQL

MySQL复习笔记I_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
풀어 주다: 2016-06-01 13:30:52
원래의
1048명이 탐색했습니다.

bitsCN.com

MySQL复习笔记I

 

[sql] #查看包含哪些数据库  show databases;    #使用名为 test 的数据库  use test;    #最简单的(tinyint 默认是 3 个字节,但可以显式地指定为 1 个字节;unsigned 须跟在后面)  create table tb0 (  id int not null,  name char(20),  age tinyint(1) unsigned default 0  );      #带主键的  create table tb1 (  id int not null primary key,  name char(20)  );      #复合主键  create table tb2 (  id int not null,  name char(20),  primary key (id, name)  );      #带默认值的(check只是个摆设,mysql会直接忽略之)  create table tb3 (  id int not null default 0 primary key,  name char(20) default &#39;1&#39;,  sex char(1) not null check(sex in (&#39;M&#39;, &#39;F&#39;)),  age tinyint not null check(age >= 0 and age < 100)  );      #插入记录  insert into tb3(id,name,sex,age) values(1,"",&#39;M&#39;,99);  insert into tb3 values(2,"haha","F",888);  insert into tb3 values(3,"bruce.yang","A",23);  insert into tb3(id,sex,age) values(4,&#39;M&#39;,123);      #自增长主键(auto_increment 和 default 冲突)  create table tb4 (  id int not null auto_increment primary key,  name char(20) default &#39;hahaha&#39;  );      #插入记录  insert into tb4(id,name) values(888,"huhuhu"); #记录id为888  insert into tb4(name) values(&#39;bruce.yang&#39;); #记录id为889  insert into tb4(id,name) values(1,"hello"); #记录id为1  insert into tb4(name) values("xixi"); #记录id为890      #使用 test 数据库  use test;  #删除 test 数据库中得 tb0 表  drop table tb0;  #在删除表的过程中,如果删除一个不存在的表将会产生错误,  #这时在删除语句中加入 IF EXISTS 关键字,就可避免产生错误,具体格式如下:  drop table if exists tb0;      #注意:  #在执行 CREATE TABLE、ALTER TABLE 和 DROP TABLE 中的任何操作时,  #首先必须要选择好数据库,否则是无法对数据表进行操作的      #查看表结构  desc tb4;      #删除记录(id 为 890 的记录删除以后,新插入记录的 id 将会从 891 开始)  delete from tb4 where id=890;      #更新记录(主键字段的值也可以更新)  update tb4 set id=892 where id=891;  update tb4 set id=893,name="9lala" where id=892;  
로그인 후 복사

 


bitsCN.com
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿