sql入門

來源:互聯網
上載者:User

標籤:sql入門

查看庫:

mysql> show databases;

mysql> use wqh

查看錶:

mysql> show tables; 

建立表:

mysql> create table emp(ename varchar(10),hiredate date,sal decimal(10,2),deptno int(2));

查看建立語句:

mysql> desc emp;

mysql> show create table emp\G

修改表的屬性:

mysql> alter table emp modify ename varchar(15);修改列屬性

mysql> alter table emp add column age int(3);添加列

mysql> alter table emp drop column age;刪除列

mysql> alter table emp change age age2 int(10);改列名

mysql> alter table emp add brith date after ename; 修改欄位位置

mysql> alter table emp modify age2 int(10) first;調整列位置

修改表明

mysql> alter table emp rename emp1;

插入資料:

mysql> insert into emp (ename,hiredate,sal,deptno) values(‘zzx1‘,‘2000-01-01‘,‘2000‘,1);

mysql> insert into emp values(‘qwe2‘,‘2000-01-01‘,‘2000‘,2); 

mysql> insert into emp (ename,sal) values(‘ccv3‘,‘2000‘);

mysql> insert into emp (ename,sal) values(‘ccv3‘,‘2000‘),(‘ccv4‘,‘3000‘);

更新記錄:

mysql> update emp set sal=4000 where  ename=‘qwe2‘;

mysql> update emp a,dept b set a.sal=a.sal*b.deptno,b.deptname=a.ename where a.deptno=b.deptno; 同時更新多個表中的資料

刪除記錄:

mysql> delete from emp where ename="zzx1";

mysql> delete a,b from emp a,dept b where a.deptno=b.deptno and a.deptno=2;





























sql入門

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.