How to change the database script file from sh format to SQL format in Linux

Source: Internet
Author: User
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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.