저장 프로시저에서 SHOW CREATE TABLE을 실행하려면 SHOW CREATE TABLE을 사용하십시오. 먼저 테이블을 생성하겠습니다 -
mysql> create table DemoTable2011 -> ( -> StudentId int NOT NULL AUTO_INCREMENT, -> StudentName varchar(20), -> StudentAge int, -> StudentCountryName varchar(20), -> PRIMARY KEY(StudentId) -> ); Query OK, 0 rows affected (0.80 sec)
다음은 SHOW CREATE TABLE -
을 실행하는 저장 프로시저입니다.mysql> delimiter // mysql> create procedure test_show_create_demo(table_name varchar(100)) -> begin -> set @query=concat("SHOW CREATE TABLE ",table_name); -> prepare st from @query; -> execute st; -> end -> // Query OK, 0 rows affected (0.22 sec) mysql> delimiter ;
CALL 명령을 사용하여 저장 프로시저 호출 -
mysql> call test_show_create_demo('DemoTable2011');호출
이것은 다음과 같은 출력을 생성합니다 -
+---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | DemoTable2011 | CREATE TABLE `demotable2011` ( `StudentId` int(11) NOT NULL AUTO_INCREMENT, `StudentName` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, `StudentAge` int(11) DEFAULT NULL, `StudentCountryName` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`StudentId`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci | +---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.01 sec) Query OK, 0 rows affected, 1 warning (0.06 sec)