SQL資料庫的一些操作

2022-07-01 17:57:07 字數 1480 閱讀 4354

——以 mysql為例

//登陸

mysql -u root -p

//建立乙個名為test_lib的資料庫

create database test_lib

//刪除乙個名為test_lib的資料庫

drop database test_lib

//選擇test_lib資料庫

use test_lib

//新增乙個包含3列的表(table)[參考](

create table table1

(column_name1 data_type(size),

column_name2 data_type(size),

column_name3 data_type(size)

);//刪除乙個表(table)

drop table table_name

//新增乙個列(表頭)

alter table table_name add column column_name varchar(45);

//刪除一列

alter table table1 drop column column1;

//新增一行(兩種方式,指定列,或者不指定列)

insert into table_name (column1,column2,column3,...) values ('value1','value2','value3',...);

insert into table_name values ('value1','value2','value3',...);

//刪除一行

delete from table_name where column5='ccc';

//顯示test_lib的所有資料

seclet *from test_lib

//檢視有多少個database

show databases;

//檢視某個database有多少個table

show tables;

//檢視當前使用的資料庫

select database();

//檢視資料庫使用埠

show variables like 'port';

//檢視資料庫編碼

show variables like 'character%';

//檢視資料庫的所有使用者資訊

select distinct concat('user: ''',user,'''@''',host,''';') as query from mysql.user;

//檢視某個具體使用者的許可權

show grants for 'root'@'localhost';

//檢視資料庫當前連線數,併發數

show status like 'threads%';

//檢視資料檔案存放路徑

show variables like '%datadir%';

資料庫 資料庫sql一些操作

空關係 none 方法返回可以在鏈式呼叫中使用的 不包含任何記錄的空關係。在這個空關係上應用後續條件鏈,會繼續生成空關係。對於可能返回零結果 但又需要在鏈式呼叫中使用的方法或作用域,可以使用 none 方法來提供返回值。article.none 返回乙個空 relation 物件,而且不執行查詢 下...

資料庫 sql一些操作記錄

常用的條件表示式 條件表示式舉例1 表示式舉例2說明 使用 判斷相等 score 80 name abc 字串需要用單引號括起來 使用 判斷大於 score 80 name abc 字串比較根據ascii碼,中文字元比較根據資料庫設定 使用 判斷大於或相等 score 80 name abc 使用 ...

oracle 資料庫的一些sql操作

時間字段查詢的sql語句 select from mycontent t where t.create date to date 2010 06 21 yyyy mm dd 修改時間欄位的sql語句 update mycontent t set t.create date to date 2012....