Home  >  Article  >  Database  >  Linux下如何将数据库脚本文件从sh格式变为sql格式

Linux下如何将数据库脚本文件从sh格式变为sql格式

WBOY
WBOYOriginal
2016-06-07 16:50:391204browse

在从事软件开发的过程中,经常会涉及到在Linux下将数据库脚本文件从sh格式变为sql格式的问题。本文以一个实际的脚本文件为例,说

在从事软件开发的过程中,经常会涉及到在Linux下将数据库脚本文件从sh格式变为sql格式的问题。本文以一个实际的脚本文件为例,说明格式转换的过程。

      1. sh文件内容

      本文中的文件名为example.sh,,其内容如下:

#!/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

 

create table tb_employeeinfo

(

    employeeno        varchar(20)      not null,      -- 员工工号

    employeename    varchar(20)      not null,      -- 员工姓名

    employeeage      int                          null      -- 员工年龄

);

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

 

        说明:

        (1)  本文件用于创建tb_employeeinfo表,生成的脚本文件名为example.sql。

        (2)  Init函数用于在屏幕上输出信息,CreateTable函数用于创建数据表。

        (3)  在sh文件的结尾,要按顺序将本文件所包含的所有函数罗列出来,如本文件包括的函数是Init和CreateTable。

更多详情见请继续阅读下一页的精彩内容:

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn