PowerDesigner實(shí)現(xiàn)導(dǎo)出的SQL語句附帶主鍵

字號:

SQL Server 2000下,pd導(dǎo)出sql語句,表是不帶主鍵的。但是這個問題可以解決:
    雙擊你在pd里面所建的表--》選擇“perview”,可以查看這張表的建表語句。
    舉個例子:表1
    if exists (select 1
    from sysobjects
    where id = object_id('T_SA_FIELD')
    and type = 'U')
    drop table T_SA_FIELD
    go
    /*==============================================================*/
    /* Table: T_SA_FIELD */
    /*==============================================================*/
    create table T_SA_FIELD (
    SAFIELDRECID int null,
    SARECID int null,
    FIELDNAME varchar(100) null,
    FIELDTYPE DECIMAL null
    )
    go
    其中,SAFIELDRECID是此表的主鍵自增id,但是導(dǎo)出來的時候主鍵卻不對。怎么解決呢?
    看看pd的建表解決這個問題的正確例子吧:
    if exists (select 1
    from sysobjects
    where id = object_id('dbo.T_SA_FIELD')
    and type = 'U')
    drop table dbo.T_SA_FIELD
    go
    /*==============================================================*/
    /* Table: T_SA_FIELD */
    /*==============================================================*/
    create table dbo.T_SA_FIELD (
    SAFIELDRECID int identity(1, 1),
    SARECID int null,
    FIELDNAME varchar(1000) null,
    constraint PK_T_SA_FIELD primary key (SAFIELDRECID)
    ON [PRIMARY]
    )
    ON [PRIMARY]
    go
    看看這個語句上面帶顏色的部分,對比一下區(qū)別,很明顯的。我是把SQL Server 2000里的數(shù)據(jù)庫導(dǎo)成sql語句腳本。
    然后打開pd,選擇“file”--“reverse engineer”--“database”選擇剛才導(dǎo)出的sql腳本,在sql腳本里面吧相應(yīng)的內(nèi)容按著上面的改一下保存。然后再選擇“file”--“reverse engineer”--“database”,把剛改過的sql腳本導(dǎo)入pd就OK了。