#数据库MySQL 6.7 use sakila;
#查询表名
show tables;
#
SELECT TABLE_NAME,TABLE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='sakila'; select column_name from information_schema.columns where table_schema='sakila' and table_name='actor';
#表结构 字段名, 类型,长度
select * from information_schema.columns where table_schema='sakila' and table_name='actor'; # GetTables
SELECT TABLE_NAME, '' OWNER, CREATE_TIME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'sakila' AND TABLE_TYPE = 'BASE TABLE' ORDER BY 1;
#GetTableColumns
SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_OCTET_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE, CASE IS_NULLABLE WHEN 'NO' THEN 0 ELSE 1 END IS_NULLABLE, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'sakila' AND TABLE_NAME = 'address' ORDER BY ORDINAL_POSITION;
#GetViews
SELECT TABLE_NAME, '' OWNER, CREATE_TIME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'sakila' AND TABLE_TYPE = 'VIEW' ORDER BY 1;
#GetViewColumns
SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_OCTET_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE, CASE IS_NULLABLE WHEN 'NO' THEN 0 ELSE 1 END IS_NULLABLE, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'sakila' AND TABLE_NAME = 'actor_info' ORDER BY ORDINAL_POSITION;
#GetTablePrimaryKey
SELECT t1.CONSTRAINT_NAME, t1.COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE t1 INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS t2 ON t2.TABLE_SCHEMA = t1.TABLE_SCHEMA AND t2.TABLE_NAME = t1.TABLE_NAME AND t2.CONSTRAINT_NAME = t1.CONSTRAINT_NAME WHERE t1.TABLE_SCHEMA = 'sakila' AND t1.TABLE_NAME = 'address' AND t2.CONSTRAINT_TYPE = 'PRIMARY KEY' ORDER BY t1.ORDINAL_POSITION;
#GetTableIndexes
SELECT INDEX_NAME, COUNT(*) AS COLUMN_COUNT, MAX(NON_UNIQUE) NON_UNIQUE, CASE INDEX_NAME WHEN 'PRIMARY' THEN 1 ELSE 0 END IS_PRIMARY
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = 'sakila' AND TABLE_NAME = 'customer'
GROUP BY INDEX_NAME
ORDER BY INDEX_NAME; SELECT INDEX_NAME, COLUMN_NAME
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = 'sakila' AND TABLE_NAME = 'customer'
ORDER BY INDEX_NAME, SEQ_IN_INDEX;
#GetMyTableKeys
SELECT CONSTRAINT_NAME
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS t1
WHERE t1.TABLE_SCHEMA = 'sakila' AND t1.TABLE_NAME = 'customer'
AND CONSTRAINT_TYPE = 'FOREIGN KEY'; SELECT t1.CONSTRAINT_NAME, t1.COLUMN_NAME, t1.POSITION_IN_UNIQUE_CONSTRAINT,t1.REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE t1
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS t2
ON t2.TABLE_SCHEMA = t1.TABLE_SCHEMA
AND t2.TABLE_NAME = t1.TABLE_NAME
AND t2.CONSTRAINT_NAME = t1.CONSTRAINT_NAME
WHERE t1.TABLE_SCHEMA = 'sakila' AND t1.TABLE_NAME = 'customer'
AND t2.CONSTRAINT_TYPE = 'FOREIGN KEY'
ORDER BY t1.CONSTRAINT_NAME, t1.POSITION_IN_UNIQUE_CONSTRAINT; #GetOthersTableKeys
SELECT DISTINCT CONSTRAINT_NAME
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE t1
WHERE t1.TABLE_SCHEMA = 'sakila' AND t1.REFERENCED_TABLE_NAME = 'customer'; SELECT t1.CONSTRAINT_NAME, t1.TABLE_NAME, t1.COLUMN_NAME, t1.POSITION_IN_UNIQUE_CONSTRAINT, t1.REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE t1
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS t2
ON t2.TABLE_SCHEMA = t1.TABLE_SCHEMA
AND t2.TABLE_NAME = t1.TABLE_NAME
AND t2.CONSTRAINT_NAME = t1.CONSTRAINT_NAME
WHERE t1.TABLE_SCHEMA = 'sakila' AND t1.REFERENCED_TABLE_NAME = 'customer'
AND t2.CONSTRAINT_TYPE = 'FOREIGN KEY'
ORDER BY t1.CONSTRAINT_NAME, t1.POSITION_IN_UNIQUE_CONSTRAINT;
#GetViewText
SELECT VIEW_DEFINITION FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = 'sakila' AND TABLE_NAME = 'actor_info';
# GetCommands
SELECT ROUTINE_NAME, '' OWNER, CREATED FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'sakila' AND ROUTINE_TYPE = 'PROCEDURE' ORDER BY 1;
#GetCommandParameters
#GetCommandText
SELECT ROUTINE_DEFINITION FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'sakila' AND ROUTINE_NAME = 'film_in_stock' #存储过程
sql:MySQL 6.7 表,视图,存储过程结构查询的更多相关文章
-
sql:sql server,MySQL,PostgreSQL的表,视图,存储过程结构查询
sql server 2005: --SQL SERVER 2005 生成代码需要知道的SQL语句 use LibrarySystem --查询当前数据库所有表和其的主键字段,字段类型,长度,是否为空 ...
-
sql:Oracle11g 表,视图,存储过程结构查询
-- Oracle 11 G --20160921 涂聚文再次修改 --Geovin Du --GetTables SELECT owner, object_name, created FROM al ...
-
SQL基础随记2 视图 存储过程
SQL基础随记2 视图 存储过程 View CREATE/ALTER/DROP VIEW ViewName as SELECT(...) 可以在视图的基础上继续创建视图,即,将之前创建的视图当做表 ...
-
SQLServer2008/2012 删除所有表视图存储过程
SQLServer2008/2012 删除所有表视图存储过程 -------------------删除所有的表-------------------use xuwenbin111--/第1步**** ...
-
sql server 通用修改表数据存储过程
ALTER PROC [dbo].[UpdateTableData] ), ), ), ), ) AS BEGIN ) SET @sql ='UPDATE '+@TableName; --获取SqlS ...
-
sql 判断 表 视图 存储过程 存在 然后 删除
sql 判断 函数 存储过程是否存在的方法 (2010-12-03 10:08:57) 转载▼ 下面为您介绍sql下用了判断各种资源是否存在的代码,需要的朋友可以参考下,希望对您学习sql的函 ...
-
MYSQL批量创建表的存储过程
因为业务需要,创建了100个表,但是这些表的结构都是一样的,作为程序员,就是要解决这种重复劳动.然而这种事情还要单独写个php脚本的话太麻烦了吧,所以就干脆学了一下直接用Mysql存储过程怎么实现: ...
-
sql通用分页自定义表条件存储过程
create PROCEDURE PrcTestByPage ( @tablename varchar(50), @selectfilter varchar(100), @orderbyfilter ...
-
oracle 表 视图 存储过程 序列 job
table 表 --delete table drop table Test1; -- Create table create table TEST1 ( ID NUMBER, T_N ...
随机推荐
-
POJ3694 Network(边双连通分量+缩点+LCA)
题目大概是给一张图,动态加边动态求割边数. 本想着求出边双连通分量后缩点,然后构成的树用树链剖分+线段树去维护路径上的边数和..好像好难写.. 看了别人的解法,这题有更简单的算法: 在任意两点添边,那 ...
-
卸载安装失败的sqlserver2008 R2
安装sqlserver2008失败,无法正常卸载. 从 计算机 控制面板 卸载时有如图弹窗 并且在 控制面板 中找不到如图的各种插件. 百般无奈之后,发现下载安装windows install ...
-
swift - use backslash to add the value in the string
There’s an even simpler way to include values in strings: Write the value in parentheses, and write ...
-
JS中的toString方法
JS中的所有对象都具有toString方法,它把一个变量隐式转换为字符串 Number类型的对象的toString()方法比较特殊,有默认模式和基模式两种 默认模式: 无论我们用什么表示法声明数字变量 ...
-
怎样解题 (G. 波利亚 著)
第一部分 (已看) 目的 1. 帮助学生 2. 问题,建议,思维活动 3. 普遍性 4. 常识 5. 教师和学生,模仿和实践 主要部分,主要问题 6. 四个阶段 7. 理解题目 8. 例子 9. 拟订 ...
-
php 正则获取字符串中的汉字preg_match_all
preg_match_all('/[\x{4e00}-\x{9fff}]+/u', $list[$i]['iparr'], $matches); $list[$i]['iparr'] = join(' ...
-
poj1269 intersecting lines【计算几何】
We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a p ...
-
iOS边练边学--通知机制和键盘处理小练习
一.发送通知 NSNotification *note = [NSNotification notificationWithName:@"通知的名称,随便写,例如:你妈叫你回家吃饭" ...
-
c#二维码建立与识别
QrCodeEncodingOptions options = new QrCodeEncodingOptions(); options.CharacterSet = "UTF-8" ...
-
【BZOJ】1954: Pku3764 The xor-longest Path
[算法]trie树+xor路径 [题解] 套路1:统计从根到每个点的xor路径和,由于xor的自反性,两个点到根的xor路径和异或起来就得到两点间路径和. 然后问题就是找到n个值中异或值最大的两个值, ...