建设门户网站培训通知,个人做医疗类网站违法,婴儿衣服做的网站好,安徽手机网站建设创建数据库#xff1a;
create database 数据库名字; 删除数据库:
drop database 数据库名字; 查看数据库:
show databases; 切换数据库:
use databasename; select database(); Create table 表名#xff08;列名 数据类型 [约束]#xff0c;列名 数据类型 [约束]
create database 数据库名字; 删除数据库:
drop database 数据库名字; 查看数据库:
show databases; 切换数据库:
use databasename; select database(); Create table 表名列名 数据类型 [约束]列名 数据类型 [约束]列名 数据类型 [约束] 删除表
drop table 表名 查看表结构:
desc 表名; 查看建表的语句
show create table表名;
insert update delete
show variables like char%;
show variables like collation%;
sudo vim /etc/mysql/my.cnf
添加以下内容
[mysqld]
collation-server utf8_unicode_ci
init-connectSET NAMES utf8
character-set-server utf8
重启
service mysql restart alter 修改表结构
添加字段
alter table 表名 add [column] 字段名 数据类型 [约束]; 删除字段:
alter table 表名 drop [column] 字段名; 修改字段的名称和类型
alter table 表名 change 旧字段名 新字段名 数据类型 [约束]; 修改字段的类型
alter table 表名 modify 字段名 新的数据类型 [约束]; 约束:
主键约束 主键 唯一 not null primary key
自增 auto_increment
create table food(id int primary key auto_increment,name varchar(20),price float) 非空约束:
not null
create table qq(id int primary key auto_increment,nick_name varchar(16) not null,password varchar(64) not null,qq_no varchar(10) not null); 默认值约束:
default
create table book(id int primary key auto_increment,bname varchar(30) not null, publisher varchar(50) default 默认值); insert into book(bname,publisher) values (daomubijia,null) select * from book; insert into book(bname,publisher) values(daomubiji,default); 唯一约束:
unique 保证数据的唯一性
但是允许null
create table user(id int primary key auto_increment,username varchar(16) unique,password varchar(64) not null,phone char(11) unique not null); 检查约束mysql ----》 不支持 check
create table user(id int primary key auto_increment,username varchar(16) unique,password varchar(64) not null,phone char(11) unique,gender enum(男,女)); 外键约束:
foreign key
ALTER TABLE score1 ADD CONSTRAINT fk_sid FOREIGN KEY(sid) REFERENCES stu(sid) 一张表可以有多个外键只能有一个主键idusernamephone username phone
admin 18900001111
admin 18900001112 添加数据:
insert into 表名(id,name,age) values(值1值2值3) id name age 101 aa 19 修改数据:
update 表名 set 字段名新值 ----》 更新该字段下的所有的值 update 表名 set 字段名新值 where 条件 案例 update student set age 18; update student set age19 where id 3; update student set age 20 where id 1 or id5; update student set age age1 where id2; update student set ageage1 where id in (2,4,5,8,10); -- 1-100 50~70 update student set age age1 where id50 and id70; update student set age age1 where id between 50 and 70; update student set ageage1,namelaowang where id 4; 删除数据: delete from 表名 【where 条件】 delete from student where id4;