ホームページ >データベース >mysql チュートリアル >ストアド プロシージャを使用して MySQL スキーマを GitHub マークダウンにエクスポートするにはどうすればよいですか?
MySQL スキーマは、ストアド プロシージャを使用して GitHub マークダウン形式にエクスポートできます。次に、2 つのストアド プロシージャを使用した例を示します。これらをチェーンして目的の出力を実現できます。
ストアド プロシージャのチェーン
最初のストアド プロシージャは、レポート用のデータを準備します。
CREATE PROCEDURE `Reporting101a`.`describeTables_v2a`( IN dbName varchar(100), -- the dbname to report table structures OUT theSession int, -- OUT parameter for session# assigned IN deleteSessionRows BOOL, -- true for delete rows when done from main reporting table for this session# IN callTheSecondStoredProc BOOL -- TRUE = output is from Pretty output in Second Stored Proc. FALSE= not so pretty output ) BEGIN DECLARE thisTable CHAR(100); DROP TEMPORARY TABLE IF EXISTS Reporting101a.tOutput; CREATE TEMPORARY TABLE Reporting101a.tOutput ( id int auto_increment primary key, tblName varchar(100) not null, ordVal int not null, cField varchar(100) not null, cType varchar(100) not null, cNull varchar(100) not null, cKey varchar(100) not null, cDefault varchar(100) null, cExtra varchar(100) null ); INSERT Reporting101a.tOutput(tblName,ordVal,cField,cType,cNull,cKey,cDefault,cExtra) SELECT TABLE_NAME,ORDINAL_POSITION,COLUMN_NAME AS Field, COLUMN_TYPE AS TYPE, RPAD(IS_NULLABLE,4,' ') AS 'Null', RPAD(COLUMN_KEY,3,' ') AS 'Key',RPAD(COLUMN_DEFAULT,7,' ') AS 'DEFAULT',EXTRA AS Extra FROM information_schema.columns WHERE table_schema = dbName ORDER BY table_name,ordinal_position; -- select * from information_schema.columns WHERE table_schema = '57security' order by table_name,ordinal_position; ... END$$
2 番目のストアド プロシージャは、カーソルとMySQL の DESCRIBE コマンドに似た、きれいな出力を生成するための特別なテーブル。
CREATE PROCEDURE `Reporting101a`.`Print_Tables_Like_Describe`( pSessionId INT ) BEGIN DECLARE done INT DEFAULT FALSE; ... CREATE TABLE IF NOT EXISTS Reporting101a.reportOutput ( lineNum INT AUTO_INCREMENT PRIMARY KEY, sessionId INT NOT NULL, lineOut varchar(100) NOT NULL ); ... END$$
使用法
必要なパラメータを使用して最初のストアド プロシージャを呼び出します。パラメータ。
SET @theOutVar =-1; -- A variable used as the OUT variable below -- See **Note3** -- Note: with `TRUE` as the 4th parameter, this is a one call deal. Meaning, you are done. call Reporting101a.describeTables_v2a('stackoverflow',@theOutVar,false,true); -- See **Note4** -- Primarily used if the 4th parameter above is false call Reporting101a.Print_Tables_Like_Describe(@theOutVar); -- loads data for prettier results in chunk format.
出力
出力は reportOutput テーブルに生成され、次のように取得できます:
select lineOut as '' from Reporting101a.reportOutput where sessionId=pSessionId order by lineNum;
以上がストアド プロシージャを使用して MySQL スキーマを GitHub マークダウンにエクスポートするにはどうすればよいですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。