數據庫中的DDL和DML語言


“D:\mysql-5.6.22-winx64\bin”添加到系統環境變量path中了,然后在任意目錄可訪問mysql等命令,這樣如登錄等操作就不需要進入MySQL安裝目錄才好執行!j在最后記得還要加個;.;。

MySQL下載(兩個):
網址: www.oracle.com
1)下載MySQL Community Server (GPL) ---MySQL數據庫
2) MySQL Connectors ---jdbc驅動

登錄: mysql -u root -p1234

查看有哪些數據庫: show databases;
打開一個數據庫: use 數據庫名;
查看該打開數據庫中有哪些表格: show tables;

DBA:
創建一個新用戶: create user hncu identified by '1234';
給用戶授權: grant all on *.* to 'hncu'@'%' with grant option;
※※※※注意,創建新用戶之后,要關閉並重啟MySql服務器才會生效!

常用數據庫產品: SQL Server, Oracle, MySQL

SQL語言大小寫不敏感


一、DDL(數據定義語言,Data Definition Language)
建庫、建表、設置約束等:create\drop\alter

1、創建數據庫:
create database IF NOT EXISTS hncu CHARACTER SET utf8;

2、創建表格:
use hncu;
create table IF NOT EXISTS stud(
id int,
name varchar(30),
age int
);

3、更改表結構(設置約束)
desc stud; //查看表結構
alter table stud drop column age;
alter table stud add column age int;

4、刪除表、刪除數據庫
drop table stud;
drop database hncu;


二、DML (數據操縱語言,Data Manipulation Language )
主要指數據的增刪查改: Select\delete\update\insert\call

select * from stud;
select name,age from stud; //查詢指定的列
select name as 姓名, age as 年齡 from stud;
※※切記:表字段(Field,表頭)一定要用英文,如果要顯示成中文表頭,用別名來解決。


insert into stud values(2,'張三',22);
insert into stud(id,age) values(4,23); //指定字段名的賦值,效率更高
delete from stud where id=4;
update stud set age = age+1; //給所有學生的年齡加1


//導入腳本代碼
source d:\a\1.sql

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM