2022-10-20
閱讀量:
410
mysql 學(xué)習(xí)1- mysql入門語句
## 第一部分 MySql入門語句 -- 1 查看系統(tǒng)中有哪些數(shù)據(jù)庫 show databases; -- 2 創(chuàng)建test數(shù)據(jù)庫 create database test2; -- 3 選擇進(jìn)入數(shù)據(jù)庫 use test2; -- 4 刪除數(shù)據(jù)庫(慎用!) #drop database test2; -- 5 創(chuàng)建數(shù)據(jù)表 create table dept( #創(chuàng)建dept部門表 deptno int primary key, #部門編號(hào) dname varchar(10), #部門名稱 loc varchar(15) #城市 ); create table emp( #創(chuàng)建emp員工表 empno int primary key auto_increment, #員工編號(hào) ename varchar(10) unique key, #員工姓名 job varchar(15) not null, #職位 mgr int, #直屬領(lǐng)導(dǎo) hiredate date, #入職日期 sal decimal default 0, #工資 comm decimal, #提成 deptno int, #部門編號(hào) foreign key(deptno) references dept(deptno) ); -- 6 查看當(dāng)前數(shù)據(jù)庫中有哪些表 show tables; -- 7 查看表結(jié)構(gòu) describe dept; desc emp; -- 8 刪除數(shù)據(jù)表(慎用!) # drop table dept; 刪除表的全部 # truncate table emp; # 清空表的數(shù)據(jù),但保留表結(jié)構(gòu)。 -- 9 插入數(shù)據(jù): # 字段名與字段值的數(shù)據(jù)類型、個(gè)數(shù)、順序必須一一對(duì)應(yīng) insert into dept(dname,deptno,loc) values ('accounting',10,'new york'),('research',20,'dallas'); # 與建表時(shí)的表結(jié)構(gòu)字段順序一一對(duì)應(yīng) insert into dept values (30,'sales','chicago'),(40,'operations','boston'); -- 10 查看表中的所有數(shù)據(jù) select * from dept; select * from emp;






評(píng)論(0)


暫無數(shù)據(jù)
CDA考試動(dòng)態(tài)
CDA報(bào)考指南
推薦帖子
0條評(píng)論
1條評(píng)論
0條評(píng)論