In the process of software development, it often involves changing the database script file from sh format to SQL format in Linux. This document uses an actual script file as an example to describe
In the process of software development, it often involves changing the database script file from sh format to SQL format in Linux. This document uses an actual script file as an example to describe
In the process of software development, it often involves changing the database script file from sh format to SQL format in Linux. This document uses an actual script file as an example to describe the format conversion process.
1. sh File Content
The file name in this article is example. sh, and its content is as follows:
#! /Bin/bash
Function Init ()
{
If [-f "example. SQL"]
Then
Echo "example. SQL is exits and is deleting it, then recreate it"
Rm-fexample. SQL
Else
Echo "example. SQL no exits and is creating it"
Fi
Echo "usezxdbp_166"> example. SQL
Echo "go"> example. SQL
}
Function CreateTable ()
{
Cat> example. SQL <EOF
Create table tb_employeeinfo
(
Employeeno varchar (20) not null, -- employee ID
Employeename varchar (20) not null, -- employee name
Employeeage int null -- employee age
);
Create unique index idx1_tb_employeeinfo ontb_employeeinfo (employeeno );
Create index idx2_tb_employeeinfo ontb_employeeinfo (employeename );
Print 'create table tb_employeeinfo OK'
Go
EOF
}
# Execute function
Init
CreateTable
Note:
(1) This file is used to create the tb_employeeinfo table. The generated script file name is example. SQL.
(2) The Init function is used to output information on the screen, and the CreateTable function is used to create a data table.
(3) At the end of the sh file, list all functions contained in this file in sequence. For example, the functions included in this file are Init and CreateTable.
For more details, please continue to read the highlights on the next page: