本文整理汇总了C#中ObjectName.OnDatabase方法的典型用法代码示例。如果您正苦于以下问题:C# ObjectName.OnDatabase方法的具体用法?C# ObjectName.OnDatabase怎么用?C# ObjectName.OnDatabase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObjectName
的用法示例。
在下文中一共展示了ObjectName.OnDatabase方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DropPrimaryKeyConstraint
public static SqlPreCommandSimple DropPrimaryKeyConstraint(ObjectName tableName)
{
DatabaseName db = tableName.Schema.Database;
var tn = tableName.OnDatabase(null);
string varName = "PrimaryKey_Constraint_" + tn.Name;
string command = @"
DECLARE @sql nvarchar(max)
SELECT @sql = 'ALTER TABLE {Table} DROP CONSTRAINT [' + kc.name + '];'
FROM DB.sys.key_constraints kc
WHERE kc.parent_object_id = OBJECT_ID('{FullTable}')
EXEC DB.dbo.sp_executesql @sql"
.Replace("DB.", db == null ? null : (db.ToString() + "."))
.Replace("@sql", "@" + varName)
.Replace("{FullTable}", tableName.ToString())
.Replace("{Table}", tn.ToString());
return new SqlPreCommandSimple(command);
}
示例2: DropDefaultConstraint
public static SqlPreCommandSimple DropDefaultConstraint(ObjectName tableName, string columnName)
{
DatabaseName db = tableName.Schema.Database;
var tn = tableName.OnDatabase(null);
string varName = "Constraint_" + tableName.Name + "_" + columnName;
string command = @"DECLARE @sql nvarchar(max)
SELECT @sql = 'ALTER TABLE {Table} DROP CONSTRAINT [' + dc.name + '];'
FROM DB.sys.default_constraints dc
JOIN DB.sys.columns c ON dc.parent_object_id = c.object_id AND dc.parent_column_id = c.column_id
WHERE c.object_id = OBJECT_ID('{FullTable}') AND c.name = '{Column}'
EXEC DB.dbo.sp_executesql @sql
"
.Replace("DB.", db == null ? null : (db.ToString() + "."))
.Replace("@sql", "@" + varName)
.Replace("{FullTable}", tableName.ToString())
.Replace("{Table}", tn.ToString())
.Replace("{Column}", columnName);
return new SqlPreCommandSimple(command);
}
示例3: RenameForeignKey
public static SqlPreCommand RenameForeignKey(ObjectName foreignKeyName, string newName)
{
return SP_RENAME(foreignKeyName.Schema.Database, foreignKeyName.OnDatabase(null).ToString(), newName, "OBJECT");
}
示例4: RenameTable
public static SqlPreCommand RenameTable(ObjectName oldName, string newName)
{
return SP_RENAME(oldName.Schema.Database, oldName.OnDatabase(null).ToString(), newName, null);
}
示例5: DropIndex
public static SqlPreCommand DropIndex(ObjectName objectName, string indexName)
{
if (objectName.Schema.Database == null)
return new SqlPreCommandSimple("DROP INDEX {0} ON {1}".FormatWith(indexName.SqlEscape(), objectName));
else
return new SqlPreCommandSimple("EXEC {0}.dbo.sp_executesql N'DROP INDEX {1} ON {2}'"
.FormatWith(objectName.Schema.Database.ToString().SqlEscape(), indexName.SqlEscape(), objectName.OnDatabase(null).ToString()));
}