數據庫基礎使用
數據庫的操作:
1.使用命令行連接數據庫。在命令行鍵入”mysql -u root -p”命令。
2.列出MySQL數據庫管理系統的數據庫列表。在命令行鍵入”show databases;”命令。
3.創建數據庫。在命令行鍵入”create database database_name;”命令。使用”show databases;”命令可以看到創建的數據庫已經成功加入到數據庫列表中。
4.刪除數據庫。在命令行鍵入”drop database database_name;”命令。使用”show databases;”命令可以看到要刪除的數據庫已經成功在數據庫列表中移除。
數據表的操作:
5.使用一個指定數據庫。在命令行鍵入”use database_name”命令。使用此命令后,所有的MySQL命令都只針對改數據庫。
6.創建數據表(創建MySQL數據表需要以下信息:表名、表字段、定義每個表字段)。在命令行鍵入”create table table_name(屬性名 數據類型 完整性約束條件,。。。)”。
7.插入數據表元素。在命令行鍵入”insert into table_name(field1,field2,...fieldN) Values (value1,value2,...,valueN)”命令。并使用”select * from table_name”查看數據表的所有數據。
8.查看指定數據庫的所有數據表列表。在命令行鍵入”show tables;”命令。
9.查看數據表的所有備注信息。在命令行鍵入”show full columns from table_name;”命令。
10.查看數據表的詳細索引信息,包括primary key(主鍵)。在命令行鍵入”show index from table_name;”命令。
11.修改表名。在命令行鍵入”alter table used_table_name rename new_table_name;”命令。
12.修改字段的數據類型。在命令行鍵入”alter table table_name modify attribute_name date_type;”命令。
13.修改字段名。在命令行鍵入”alter table table_name change used_attribute_name new_attribute_name new_data_type;”命令。
14.增加數據表字段。在命令行鍵入”alter table table_name add attribute_name data_type [integrity_constraint];”命
15.刪除字段。在命令行鍵入”alter table table_name drop attribute_name;”命令。
16.數據表的刪除。在命令行鍵入”drop table table_name;”命令。
數據表的操作——查詢語句:
17.取出表中所有列。在命令行鍵入”select * from table_name;”命令。也可以將*換成屬性名取出要取出的列。
18.where子句,做判斷用取出符合條件的數據。在命令行鍵入”select * from table_name where judgement_condition;”命令。
19.使用update更新數據表中元素的屬性值。在命令行鍵入”update table_name set update_data where judgment_condition;”命令。
20.使用delete語句刪除數據表中的記錄。在命令行鍵入”delete from table_name where judgement_condition;”命令。