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;