sqlserver转mysql

昨天朋友问我sqlserver转mysql杂么弄,我说百度呀,结果百度一顿还是有些问题 最后写了个脚本转换一下 顺便自己也学习一下shell脚本

笔记先贴这里 后续整理一下

USE [huaxindev]
GO
/****** Object:  Table [dbo].[JCRttt]    Script Date: 06/06/2013 18:14:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO    CREATE TABLE
CREATE TABLE [dbo].[JCRttt](
	[RtyID] [varchar](20) NOT NULL,
	[CaseNo] [varchar](20) NULL,
	[RiskReCode] [char](10) NULL,
	[Money] [numeric](16, 2) NULL,
 CONSTRAINT [PK_JCRESPONBILITY] PRIMARY KEY NONCLUSTERED 
(
	[ResponsibilityID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[JCReee]    Script Date: 06/06/2013 18:14:22 ******/

 脚本如下

#!/bin/bash
PROJECT_NAME=$1
NAME0="\/\*\*\*\*\*\*"
NAME3='CREATE TABLE '
NAME1='CONSTRAINT'
NAME2='\*\*\*\*\*\*\/'
NAME4="print 'Processed"
NAME5="INSERT"
NAME5="INSERT"

sed -i 's/\[dbo\].//g' $1

sed -i 's/\[//g' $1

sed -i 's/\]//g' $1

echo *********快乐的分割线1*********
beg=0
end=0
lastValue=0
index=0

value1=`grep "$NAME4" -n $1 | cut -d ":" -f1 | head -50000`
echo value1=$value1
for i in  $value1
do    
    index=$(($index+1))
    
    beg=$(($i-1-$lastValue))
    #echo 开始:$beg
    
    end=$(($beg+1))    
    #echo 结束:$end
    
    lastValue=$(($lastValue+$end-$beg+1))
    #echo lastValue=$lastValue
    
    echo begin:$index 开始:$beg 结束:$end
    b=$(($beg))
    e=$(($end))
    sed -n "$b p" $1 
    sed -n "$e p" $1 

    sed -i "${beg},${end}d" $1

    
done

echo *********快乐的分割线2*********
beg=0
end=0
lastValue=0
index=0

value1=`grep "$NAME0" -n $1 | cut -d ":" -f1 | head -50000`
echo value1=$value1
value2=`grep "$NAME3" -n $1 | cut -d ":" -f1 | head -50000`
echo value2=$value2
for i in  $value1
do
    index=$(($index+1))
    
    beg=$(($i+1-$lastValue))    
    #echo 开始:$beg
    
    for j in $value2
    do 
        if [ $j -gt $i ]; then            
            end=$j
            break;
        fi
    done
    
    end=$(($end-1-$lastValue))    
    #echo 结束:$end
    
    lastValue=$(($lastValue+$end-$beg+1))
    #echo lastValue=$lastValue

    echo begin:$index 开始:$beg 结束:$end
    b=$(($beg-1))
    e=$(($end+1))
    sed -n "$b p" $1 
    sed -n "$e p" $1 
    #echo end:$index
    
    if [ $end -le $beg ]; then    
            echo xxxxxxxxxxxxxxxxxxxxxx wrong msg xxxxxxxxxxxx
            echo 开始:$beg    
            echo 结束:$end    
            echo testssslastValue=$lastValue
    fi
    sed -i "${beg},${end}d" $1
done

sed -i 's/\/\*\*\*\*\*\*/INSERT_FUCK\/\*\*\*\*\*\*/g' $1

echo *********快乐的分割线3*********
beg=0
end=0
lastValue=0
index=0

value1=`grep "$NAME1" -n $1 | cut -d ":" -f1 | head -50000`
echo value1=$value1
value2=`grep "$NAME5" -n $1 | cut -d ":" -f1 | head -50000`
echo value2=$value2
for i in  $value1
do
    index=$(($index+1))
    beg=$(($i-$lastValue))    
    #echo 开始:$beg
    
    for j in $value2
    do 
        if [ $j -gt $i ]; then            
            end=$j
            break;
        fi
    done
    
    end=$(($end-1-$lastValue))    
    #echo 结束:$end
    
    lastValue=$(($lastValue+$end-$beg+1))
    #echo lastValue=$lastValue

    echo begin:$index 开始:$beg 结束:$end
    b=$(($beg))
    e=$(($end))
    sed -n "$b p" $1 
    sed -n "$e p" $1 
    #echo end:$index
    
    if [ $end -le $beg ]; then    
            echo xxxxxxxxxxxxxxxxxxxxxx wrong msg xxxxxxxxxxxx
            echo 开始:$beg    
            echo 结束:$end    
            echo testssslastValue=$lastValue
    fi
    sed -i "${beg},${end}d" $1
done

echo *********快乐的分割线4*********


sed -i 's/INSERT/;INSERT/g' $1

sed -i 's/\/\*\*\*\*\*\*/;\/\*\*\*\*\*\*/g' $1

sed -i 's/INSERT_FUCK;//g' $1


echo *********我日还有2种手动替换吧 麻烦死了*********

 

 

 

posted @ 2013-06-08 09:50  华仔崽  阅读(372)  评论(0编辑  收藏  举报
友情链接 JeffreyZhao  zhangziqiu 短信猫 MVC学习 .net面试问答(大汇总) python