MySQL資料命令

來源:互聯網
上載者:User

標籤:pos   alter   選擇   values   sql   刪除資料庫   insert   tab   name   

一、資料庫操作

建立資料庫create database db1 charset utf8;查看資料庫show database;show create database db1;select database();選擇資料庫use db1;刪除資料庫drop database db1;修改資料庫alter database db2 charset utf8;

二、表的建立與資料的插入

使用者表    create table user(    id int,    user varcher(16) not null unique,    pwd varcher(32) not null    foreign key(group_id) references group(id)    );使用者表的添加    insert into user(user,pwd,group_id) values    (‘冬馬和紗‘,‘123‘,‘1‘),    (‘小母豬雪菜‘,‘123‘,‘1‘),    (‘北原春希‘,‘123‘,‘2‘),    (‘‘,‘‘,‘‘);    使用者組表    create table group(    id int primary key auto_increment,    group_name varcher(16)    );多對多表    create table class2teacher(    id int primary key auto_increment,    class_id int not null,    teacher_id int,    constraint fk_class foreign key(class_id) references class,    constraint fk_teacher foreign key(teacher_id) references teacher,    unique(class_id,teacher_id)    );    insert into class2teacher(class_id,teacher_id) values    (‘‘,‘‘),    (‘‘,‘‘);

三、表查詢

連表查詢    select user.id,user.name,group_name from     user inner join group on user.group_id=group.id;子查詢    select user.name from user where group_id in     (select id from group where group_name=‘敗犬組‘);

 

MySQL資料命令

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.