mysql資料定義 Mysql 資料定義

2021-10-19 20:45:48 字數 2434 閱讀 2167

1、基本操作

刪除資料元

delete from student where name = 'qiang』; 條件刪除

delete from student;清空**

更新資料

update student set height = 180 where name = 'hong』;

update student set age = 99 where name like "h%";

萬用字元:

select * from student where name like 'hong%』; 0或多個字元

select * from student where name like 『hong_』; 乙個字元

2、表的建立&刪除

建立表create table student(

id int primary key,

name varchar(20) not null,

weight decimal(5,2) default 0,

birthday date not null

create table if not exists employee(

id int primary key auto_increment,

name varchar(50) not null,

gender enum('male', 'female'),

email varchar(100) not null unique,

salary decimal(6,2) default 0,

hiredate datetime not null,

hover set('a','b','c','d')

)engine innodb character set utf8;

預設是innodb

刪除表操作

drop database mydb;

drop database if exists mydb;

3、表的修改(alter):

修改表編碼

alter table student character set = utf8;

修改表名稱

alter table rename to|as new_name;

rename table tb_name to new_name;

修改列名稱(change)

alter table student change [column] old_name new_name int;

修改列屬性(modify):

alter table student modify [column] height varchar(13);

新增一列

alter table employee add department_id int;

alter table employee add department_id int after name;

alter table employee add department_id int first;

刪除一列

alter table tb_name drop [column] col_name;

插入資料

insert [into] employee value[s]();

insert employee values(null,'ta','male','[email protected]',100,'1999-12-12','a,b,c')

插入一行資料

insert into employee(last_name, email, hiredate) values('tb','[email protected]'.'2000-1-11');

連續插入多行資料:

insert into student values(005, '大頭',45, 165),(007,"小白",34,178),(009, 「小雲",23,189);

desc tb_name; 檢視相關字段屬性

show create database db_name; 顯示資料庫建立資訊

show create table tb_name; 顯示表建立資訊

status;("\s」) 當前連線相關資訊

show columns from tb_name; 顯示列的資訊

show full columns from tb_name; 完整字段資訊

show variables; 顯示系統變數

show variables like 'char%』; 查詢系統變數

set character_set_server = utf8; 設定系統變數值

select * from tb_name \g 列的形式顯示查詢資料

? functions 檢視幫助文件

? command 檢視指定命令的幫助文件

source filename.sql 匯入外部資料

mysql資料定義 Mysql 資料定義

1 基本操作 刪除資料元 delete from student where name qiang 條件刪除 delete from student 清空 更新資料 update student set height 180 where name hong update student set ag...

MySQL資料定義(DDL)

資料庫定義語句 檢視據庫 show databases 建立資料庫 語法 create database if notexists 資料庫名 default character set 字符集名 default collate 校對規則名 示例 create database db1 default...

mysql的定義 MySQL定義

什麼是sql sql是結構化查詢語言。什麼是資料庫 資料庫是用來儲存資料的。關聯式資料庫 多張表之間的關係。關聯式資料庫包含表 表名 列 主鍵,通過相應的關係列來產生連線關係。資料庫與資料倉儲 資料庫是用來做交易 transaction 資料倉儲是用來做分析 analytics 資料倉儲的作用在於 ...