public string FileConfigDDL() { string tbName = "S_FileInfo"; StringBuilder sql = new StringBuilder(); sql.AppendLine(" if not exists (select * from dbo.sysobjects " + "where id = object_id(N'[dbo].[" + tbName + "]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) "); StringBuilder CreateTbSql = new StringBuilder(); StringBuilder UpdateTbSql = new StringBuilder(); CreateTbSql.AppendLine(" CREATE TABLE [dbo].[" + tbName + "] ( "); CreateTbSql.AppendLine(" [ID] [varchar](50) NOT NULL,"); CreateTbSql.AppendLine(" [DocIndexID] [int] IDENTITY(1,1) NOT NULL,"); CreateTbSql.AppendLine(" [Name] [nvarchar](500) NOT NULL, "); CreateTbSql.AppendLine(" [NodeID] [varchar](50) NOT NULL, "); CreateTbSql.AppendLine(" [SpaceID] [varchar](50) NOT NULL, "); CreateTbSql.AppendLine(" [ConfigID] [varchar](50) NOT NULL, "); CreateTbSql.AppendLine(" [RelateID] [varchar](500) NULL, "); CreateTbSql.AppendLine(" [FullNodeID] [varchar](500) NOT NULL, "); CreateTbSql.AppendLine(" [ContentText] [text] NULL, "); CreateTbSql.AppendLine(" [CreateTime] [datetime] NULL, "); CreateTbSql.AppendLine(" [State] [nvarchar](50) NOT NULL, "); CreateTbSql.AppendLine(" [BorrowState] [nvarchar](50) NULL, "); CreateTbSql.AppendLine(" [BorrowUserID] [nvarchar](50) NULL, "); CreateTbSql.AppendLine(" [BorrowUserName] [nvarchar](50) NULL, "); var list = this.ToFileFieldList(); foreach (var item in list) { if (!FIleDefaultField.Contains(item.FieldName)) { CreateTbSql.AppendLine(" [" + item.FieldName + "] " + DDLHelper.GetFieldDataTypeDDL(item.DataType) + " NULL, "); } } UpdateTbSql.AppendLine(GetFileConfigAlterDDL()); CreateTbSql.AppendLine(@" CONSTRAINT [PK_S_FileInfo] PRIMARY KEY CLUSTERED ( [ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] "); CreateTbSql.AppendLine(@" ALTER TABLE [dbo].[S_FileInfo] WITH CHECK ADD CONSTRAINT [FK_S_FileInfo_S_NodeInfo] FOREIGN KEY([NodeID]) REFERENCES [dbo].[S_NodeInfo] ([ID]) ALTER TABLE [dbo].[S_FileInfo] CHECK CONSTRAINT [FK_S_FileInfo_S_NodeInfo]"); if (String.IsNullOrEmpty(UpdateTbSql.ToString().Trim())) { sql.Append(" begin " + CreateTbSql.ToString() + " end "); } else { sql.Append(" begin " + CreateTbSql.ToString() + " end else "); sql.Append(" begin " + UpdateTbSql.ToString() + " end "); } return(sql.ToString()); }
public string FileConfigDDL() { string tbName = "S_FileInfo"; StringBuilder sql = new StringBuilder(); sql.AppendLine(" if not exists (select * from dbo.sysobjects " + "where id = object_id(N'[dbo].[" + tbName + "]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) "); StringBuilder CreateTbSql = new StringBuilder(); StringBuilder UpdateTbSql = new StringBuilder(); CreateTbSql.AppendLine(" CREATE TABLE [dbo].[" + tbName + "] ( "); CreateTbSql.AppendLine(" [ID] [varchar](50) NOT NULL,"); foreach (var item in S_DOC_Space.DefaultFileAttrArray) { CreateTbSql.AppendLine(" [" + item.FileAttrField + "] " + DDLHelper.GetFieldDataTypeDDL(item.DataType) + item.DBItemNullStr + ", "); } var defaultFileAttrFields = S_DOC_Space.DefaultFileAttrArray.Select(a => a.FileAttrField).ToArray(); var list = this.ToFileFieldList(); foreach (var item in list) { if (!defaultFileAttrFields.Contains(item.FieldName)) { CreateTbSql.AppendLine(" [" + item.FieldName + "] " + DDLHelper.GetFieldDataTypeDDL(item.DataType) + " NULL, "); } } UpdateTbSql.AppendLine(GetFileConfigAlterDDL()); CreateTbSql.AppendLine(@" CONSTRAINT [PK_S_FileInfo] PRIMARY KEY CLUSTERED ( [ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] "); CreateTbSql.AppendLine(@" ALTER TABLE [dbo].[S_FileInfo] WITH CHECK ADD CONSTRAINT [FK_S_FileInfo_S_NodeInfo] FOREIGN KEY([NodeID]) REFERENCES [dbo].[S_NodeInfo] ([ID]) ALTER TABLE [dbo].[S_FileInfo] CHECK CONSTRAINT [FK_S_FileInfo_S_NodeInfo]"); if (String.IsNullOrEmpty(UpdateTbSql.ToString().Trim())) { sql.Append(" begin " + CreateTbSql.ToString() + " end "); } else { sql.Append(" begin " + CreateTbSql.ToString() + " end else "); sql.Append(" begin " + UpdateTbSql.ToString() + " end "); } return(sql.ToString()); }