資料庫(1) 資料庫管理和表管理

2021-08-23 12:18:51 字數 1262 閱讀 1594

一、資料庫管理

1、查詢所有資料庫    show databases;

2、建立資料庫 create database name (default character set utf8 指定預設字符集建立資料庫可以省略);

3、檢視資料庫的預設字符集 show create database name;

4、資料庫的增刪改

刪除資料庫 : drop database name;

修改資料庫 : alter database name;

二、表管理

1、檢視所有表 : show tables;

2、建立表 :

create table student(

->id int     (int預設長度為11),

->name varchar(20),  

->age int

3、檢視表結構    : desc student;

4、刪除表 : drop table student;

5、修改表 

(1)新增字段  : alter table student add column gender varchar(4);   

(2)刪除字段 :  alter table student drop column gender;

(3)修改字段型別 : alter table student modify column remark varchar(10);

(4)修改欄位名稱 : alter table studentchange column gender sgender varchar(2);

(5)修改表名稱 : alter table student rename to teacher;

三、增刪改查資料

1、查詢資料:  select * from student;

2、插入資料:  insert into student values(1,'張三','男',20);

3、修改資料: update student set gender='男' where id=1;

4、刪除資料:  delete from student where id=2;

1)可以帶條件刪除  2)只能刪除表的資料,不能刪除表的約束   3)使用delete from刪除的資料可以回滾(事務)

5、刪除資料的另一種方式: truncate table student 可以全表刪除

1)不能帶條件刪除  2)即可以刪除表的資料,也可以刪除表的約束 3)truncate table刪除的資料不能回滾

管理資料庫和表

第乙個字元必須是 unicode中定義的字母包括拉丁字母a z和a z,以及來自其他語言的字母字元 以及下劃線 符號或者數字符號 識別符號不能是所用rdbms的保留字。不允許嵌入空格或其他特殊字元。2.刪除資料庫 語法為 drop database 3.整型資料型別 tinyint 型 1個位元組 ...

資料庫表管理

資料的完整性 精確性 可靠性 資料喪失完整性體現在 資料可中存在不符合規定的資料或錯誤的資訊,例如 學號重複,身份證號重複,年齡為負數,薪水為負數,性別不存在 資料喪失完整性 是在設計表結構的時候造成的。保證資料的完整性 在設計表結構的時候,新增約束。約束的分類 1.實體 行 完整性約束 保證行記錄...

資料庫以及資料庫管理系統 1

資料庫 db 就是計算機中按照一定格式儲存起來的一定資料的集合。作業系統不直接對他們進行管理,而是通過資料庫管理系統 dbms 對他們進行管理。存在有很多種不同的資料庫管理系統,是按照對資料的不同阻止方式來劃分。最常見的是關係式資料庫 rdbms 還有一些不少的非關聯式資料庫。例如鍵值儲存系統,物件...