>  기사  >  데이터 베이스  >  Linux下如何将数据库脚本文件从sh格式变为sql格式

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

WBOY
WBOY원래의
2016-06-07 16:50:391200검색

在从事软件开发的过程中,经常会涉及到在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

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.