亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標(biāo)題: 比較兩個表的結(jié)構(gòu),這個用正則表達(dá)式行么? 請詳看如下 [打印本頁]

作者: whgloveu    時間: 2016-06-20 19:25
標(biāo)題: 比較兩個表的結(jié)構(gòu),這個用正則表達(dá)式行么? 請詳看如下
比如A表語句
create table A(
x char(1) not null,
y char(2) null,
primary key(x)
)

create table B(
x char(1) not null,
y char(2) null,
z char(3) null,
primary key(x)
)

我的想法是:加入這兩個建表語句分別在A.txt ,B.txt 中
然后采用正則表達(dá)式分別將這兩個表序列化(如A|x char(1) ... )(B|x char(1) ....) ,然后再比較是否相同就可以了。
請教高手幫忙實現(xiàn)。謝謝!!





作者: sunzhiguolu    時間: 2016-06-20 19:34
沒聽懂你想說啥, 比較表結(jié)構(gòu) 比較啥?
字段數(shù)量? 字段類型?  是否擁有主鍵? 字符型字段的長度? 能否為空?
作者: whgloveu    時間: 2016-06-20 19:39
回復(fù) 2# sunzhiguolu

場景: 兩個表 的表結(jié)構(gòu)定義 比較。 比如字段區(qū)別,字段類型區(qū)別,是否為空區(qū)別,主鍵定義區(qū)別 。。。只要有區(qū)別就給標(biāo)出來這兩個表有區(qū)別就行。我想還是把這個表定義弄成序列化的東西,估計才行。 有沒有其他方法,如數(shù)據(jù)庫(sybase)提供了命令工具?


   
作者: jason680    時間: 2016-06-20 19:49
回復(fù) 3# whgloveu

>> ...比如字段區(qū)別,字段類型區(qū)別,是否為空區(qū)別,主鍵定義區(qū)別 。。
   
給個例,說明唄...
怎么區(qū)別不同,要得到什么打印結(jié)果...
作者: sunzhiguolu    時間: 2016-06-20 19:52
回復(fù) 3# whgloveu
你說的這個事情, 大部分的功能只能依靠編程語言才能搞定, 正則在這里只能發(fā)揮一小部分作用.

   
作者: sunzhiguolu    時間: 2016-06-20 20:31
回復(fù) 3# whgloveu
你給 Jason680 大神詳細(xì)說下,
給個例,說明唄...
怎么區(qū)別不同,要得到什么打印結(jié)果


   
作者: whgloveu    時間: 2016-06-21 09:20
回復(fù) 4# jason680

大神,一句話,就兩個表的建表結(jié)構(gòu)只要不一樣 ,就給比較出來,顯示結(jié)果也可以為標(biāo)志位,不必是具體的信息。這樣說行不?


   
作者: whgloveu    時間: 2016-06-21 10:22
回復(fù) 5# sunzhiguolu


    謝謝,你說的對。正按你的思路在做。
作者: Herowinter    時間: 2016-06-21 10:30
常用的DB應(yīng)該都有比較table schema的工具,用正則畢竟是野路子。
作者: sunzhiguolu    時間: 2016-06-22 23:04
回復(fù) 4# jason680
大神, 您能否用 perl 代碼演示下如何進(jìn)行比較, 我一點頭緒都沒有 還請您指點, 謝謝您...

   
作者: bamqjurgg    時間: 2016-06-23 09:07
mysqldiff


alex@debian:~$ mysql -h rhel -u coldmoon -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 24
Server version: 5.5.41-MariaDB MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> use ayu;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [ayu]> desc a;
+-------+---------+------+-----+---------+-------+
| Field | Type    | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| x     | char(1) | NO   | PRI | NULL    |       |
| y     | char(2) | YES  |     | NULL    |       |
+-------+---------+------+-----+---------+-------+
2 rows in set (0.01 sec)

MariaDB [ayu]> exit
Bye
alex@debian:~$ mysql -h centos -u coldmoon -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 5.5.35-MariaDB MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> use ayu;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [ayu]> desc b;
+-------+---------+------+-----+---------+-------+
| Field | Type    | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| x     | char(1) | NO   |     | NULL    |       |
| y     | char(2) | YES  |     | NULL    |       |
| z     | char(3) | YES  |     | NULL    |       |
+-------+---------+------+-----+---------+-------+
3 rows in set (0.00 sec)

MariaDB [ayu]> exit
Bye
alex@debian:~$ mysqldiff --server1=coldmoon:123456@rhel --server2=coldmoon:123456@centos --difftype=sql ayu.a:ayu.b
# WARNING: Using a password on the command line interface can be insecure.
# server1 on rhel: ... connected.
# server2 on centos: ... connected.
# Comparing ayu.a to ayu.b                                         [FAIL]
# Transformation for --changes-for=server1:
#

ALTER TABLE `ayu`.`a`
  DROP PRIMARY KEY,
  ADD COLUMN z char(3) NULL AFTER y;

Compare failed. One or more differences found.
alex@debian:~$
alex@debian:~$
alex@debian:~$
alex@debian:~$ mysqldiff --server1=coldmoon:123456@rhel --server2=coldmoon:123456@centos --difftype=context ayu.a:ayu.b
# WARNING: Using a password on the command line interface can be insecure.
# server1 on rhel: ... connected.
# server2 on centos: ... connected.
# Comparing ayu.a to ayu.b                                         [FAIL]
# Object definitions differ. (--changes-for=server1)
#

*** ayu.a
--- ayu.b
***************
*** 1,5 ****
! CREATE TABLE `a` (
    `x` char(1) NOT NULL,
    `y` char(2) DEFAULT NULL,
!   PRIMARY KEY (`x`)
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1
--- 1,5 ----
! CREATE TABLE `b` (
    `x` char(1) NOT NULL,
    `y` char(2) DEFAULT NULL,
!   `z` char(3) DEFAULT NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1
Compare failed. One or more differences found.

作者: sunzhiguolu    時間: 2016-06-23 09:25
來一個,
  1. perl -0777 -ne '{s/\h+/ /g;s/\n/|/g;push(@a,$_)}END{print "DIFF!\n" if("$a[0]" ne "$a[-1]")}' a b
復(fù)制代碼





歡迎光臨 Chinaunix (http://72891.cn/) Powered by Discuz! X3.2