SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:
-- Create date: <2014-09-19>
-- Description: <生成数据库字典>
-- =============================================
CREATE PROCEDURE [dbo].[CreateDatabaseDictionarie]
AS
BEGIN
DECLARE @TableName nvarchar(35),@htmls varchar(8000)
DECLARE @字段名称 VARCHAR(200)
DECLARE @类型 VARCHAR(200)
DECLARE @长度 VARCHAR(200)
DECLARE @数值精度 VARCHAR(200)
DECLARE @小数位数 VARCHAR(200)
DECLARE @默认值 VARCHAR(200)
DECLARE @允许为空 VARCHAR(200)
DECLARE @外键 VARCHAR(200)
DECLARE @主键 VARCHAR(200)
DECLARE @描述 VARCHAR(200)
SET NOCOUNT ON;
DECLARE Tbls CURSOR
FOR
Select distinct Table_name
FROM INFORMATION_SCHEMA.COLUMNS
order by Table_name
OPEN Tbls
PRINT ''
PRINT ''
PRINT ' '
PRINT '
PRINT ' '
PRINT ' '
PRINT ' '
FETCH NEXT FROM Tbls INTO @TableName
WHILE @@FETCH_STATUS = 0
BEGIN
Select @htmls = '
' + @TableName + ' : '+ CAST(Value as varchar(1000)) + ''
FROM sys.extended_properties AS A
WHERE A.major_id = OBJECT_ID(@TableName)
and name = 'MS_Description' and minor_id = 0
PRINT '
'
PRINT @htmls
PRINT '
PRINT ' '
FETCH NEXT FROM Tbls INTO @TableName
END
PRINT ' '
PRINT ''
CLOSE Tbls
DEALLOCATE Tbls
END
|
private static string message = "";
public static string ExecuteNonQuery(string connextionString, CommandType commandType, string commandText, bool outputMsg)
{
if (connextionString == null || connextionString.Length == 0) throw new ArgumentNullException("connectionString");
// Create & open a SqlConnection, and dispose of it after we are done
using (SqlConnection connection = new SqlConnection(connextionString))
{
message = "";
connection.Open();
connection.InfoMessage += delegate(object sender, SqlInfoMessageEventArgs e)
{
message += "\n" + e.Message;
};
// Call the overload that takes a connection in place of the connection string
if (connection == null) throw new ArgumentNullException("connection");
// Create a command and prepare it for execution
SqlCommand cmd = new SqlCommand(commandText, connection); ;
cmd.CommandType = commandType;
// Finally, execute the command
int retval = cmd.ExecuteNonQuery();
// Detach the SqlParameters from the command object, so they can be used again
cmd.Parameters.Clear();
connection.Close();
return message;
}
}
|