sql查詢所有庫
TABLE 語句
具體語法:TABLE table_name [ORDER BY column_name] [LIMIT number [OFFSET number]]
其實從語法上看,可以排序,也可以過濾記錄集,不過比較簡單,沒有 SELECT 那麼強大。
示例 1
簡單的建一張很小的表 y1,記錄數為 10 條。表 t1,插入 10 條記錄
mysql-(ytt/3305)->create table t1 (r1 int,r2 int);
Query OK, 0 rows affected (0.02 sec)
mysql-(ytt/3305)->insert into t1
with recursive aa(a,b) as (
select 1,1
union all
select a+1,ceil(rand()*20) from aa where a < 10
) select * from aa;
Query OK, 10 rows affected (0.00 sec)
Records: 10 Duplicates: 0 Warnings: 0
- 簡單全表掃描mysql-(ytt/3305)->select * from t1;+------+------+| r1 | r2 |+------+------+| 1 | 1 || 2 | 9 || 3 | 9 || 4 | 17 || 5 | 17 || 6 | 16 || 7 | 6 || 8 | 1 || 9 | 10 || 10 | 3 |+------+------+10 rows in set (0.00 sec)
- TABLE 結果mysql-(ytt/3305)->table t1;+------+------+| r1 | r2 |+------+------+| 1 | 1 || 2 | 9 || 3 | 9 || 4 | 17 || 5 | 17 || 6 | 16 || 7 | 6 || 8 | 1 || 9 | 10 || 10 | 3 |+------+------+10 rows in set (0.00 sec)
- 看下 table 的執行計劃mysql-(ytt/3305)->explain table t1 order by r1 limit 2G*************************** 1. row *************************** id: 1 select_type: SIMPLE table: t1 partitions: NULL type: ALLpossible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 10 filtered: 100.00 Extra: Using filesort1 row in set, 1 warning (0.00 sec)
- 其實可以看到 TABLE 內部被 MySQL 轉換為 SELECT 了。mysql-(ytt/3305)->show warningsG*************************** 1. row *************************** Level: Note Code: 1003Message: /* select#1 */ select `ytt`.`t1`.`r1` AS `r1`,`ytt`.`t1`.`r2` AS `r2` from `ytt`.`t1` order by `ytt`.`t1`.`r1` limit 21 row in set (0.00 sec)
- 那其實從上面簡單的例子可以看到 TABLE 在內部被轉成了普通的 SELECT 來處理。示例 2應用於子查詢里的子表。這里要注意,內表的欄位數量必須和外表過濾的欄位數量一致。克隆表 t1 結構mysql-(ytt/3305)->create table t2 like t1;Query OK, 0 rows affected (0.02 sec)
- 克隆表 t1 數據mysql-(ytt/3305)->insert into t2 table t1;Query OK, 10 rows affected (0.00 sec)Records: 10 Duplicates: 0 Warnings: 0
- table t1 被當做內表,表 t1 有兩個欄位,必須同時滿足 t2 檢索時過濾的欄位也是兩個。mysql-(ytt/3305)->select * from t2 where (r1,r2) in (table t1);+------+------+| r1 | r2 |+------+------+| 1 | 1 || 2 | 9 || 3 | 9 || 4 | 17 || 5 | 17 || 6 | 16 || 7 | 6 || 8 | 1 || 9 | 10 || 10 | 3 |+------+------+10 rows in set (0.00 sec)
- 注意:這里如果過濾的欄位數量和子表數量不一致,則會報錯。
Ⅱ 怎樣用SQL語句查詢一個資料庫中的所有表
1、打開Microsoft SQL Server 2012,選中需要查詢所有表的資料庫。
Ⅲ 如何查看mysql有什麼資料庫
1、同時按下鍵盤上的win+r按鍵,調出運行框,並在彈出的運行框中輸入cmd後按下回稿戚車按鍵。
Ⅳ 怎樣用SQL語句查詢一個資料庫中的所有表
怎樣用SQL語句查詢一個資料庫鋒掘備中的所有表
用sql獲散旅取資料庫中銀毀所有的表名的方法:
1、oracle下:select table_name from all_tables;
2、MySQL下:select table_name from information_schema.tables where table_schema='csdb' and table_type='base table';
3、sql server下:select name from sys.tables go
Ⅳ sql查詢資料庫中有某個值的所有表
1、首先在電腦中打開Microsoft SQL Server,查詢所有資料庫。
Ⅵ 如何查找出sqlserver中所有的資料庫
閑話莫提,我們直接講解如何查看埠號。需要提的是在我的機器上安裝了sqlserver2008和sqlserver2012兩個版本的資料庫。我們首先打開sqlserver
management
studio(簡稱ssms)連接sqlserver2008的資料庫實例,然後執行如下存儲過程:
--查詢埠號
exec
sys.sp_readerrorlog
0,
1,
'listening'
查詢出來的結果如下圖所示:
從上圖我們可以看出sqlserver2008的埠號是5419。
接下來關閉ssms,再從重新打開,接著連接sqlserver2012。繼續執行上述的存儲過程,查詢結果如下圖所示:
上圖說明sqlserver2012的埠號是5413。
通過sql
server配置管理器(sscm)
首先打開sscm,如下圖所示:
然後再sqlserver網路配置中開啟tcp/ip協議
Ⅶ 怎樣用SQL語句查詢一個資料庫中的所有表
查詢一個資料庫中的所有表sql語句是show tables;
顯示所有資料庫的命令是:show databases;要查看某個資料庫先要進入資料庫使用user <資料庫名>命令;進入資料庫之後才能查詢資料庫中有哪些表。使用以下命令即可查出所有表:
show tables;
(7)sql查詢所有庫擴展閱讀
mysql資料庫的基本sql操作命令介紹:
1、顯示當前資料庫伺服器中的資料庫列表:mysql> SHOW DATABASES;
2、建立資料庫:mysql> CREATE DATABASE 庫名;
3、建立數據表:mysql> USE 庫名;mysql> CREATE TABLE 表名 (欄位名 VARCHAR(20), 字
名 CHAR(1));
4、刪除資料庫:mysql> DROP DATABASE 庫名;
5、刪除數據表:mysql> DROP TABLE 表名;
6、將表中記錄清空:mysql> DELETE FROM 表名;
7、往表中插入記錄:mysql> INSERT INTO 表名 VALUES ("hyq","M");
8、更新表中數據:mysql-> UPDATE 表名 SET 欄位名1='a',欄位名2='b' WHERE 欄位名3='c';
9、用文本方式將數據裝入數據表中:mysql> load data local infile "d:/mysql.txt" into table 表名;
10、導入.sql文件命令:mysql> USE 資料庫名;mysql> source d:/mysql.sql;