与此类似:
SELECT
*
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE CONSTRAINT_NAME = FK_TreeNodesBinaryAssets_BinaryAssets
and TABLE_NAME = TreeNodesBinaryAssets
但指数。
与此类似:
SELECT
*
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE CONSTRAINT_NAME = FK_TreeNodesBinaryAssets_BinaryAssets
and TABLE_NAME = TreeNodesBinaryAssets
但指数。
你们可以采用简单明了的办法,如:
SELECT *
FROM sys.indexes
WHERE name= YourIndexName AND object_id = OBJECT_ID( Schema.YourTableName )
INDEXPROPERTY/code 内部职能:
INDEXPROPERTY ( object_ID , index_or_statistics_name , property )
最简单的使用是<代码>。 IndexID property:
If IndexProperty(Object_Id( MyTable ), MyIndex , IndexID ) Is Null
如果该指数存在,则上述指数将退还该指数;如果该指数为t,则该指数将退回NUL
。
AdaTheDEV,我使用了你的辛迪加,并造成以下原因。
问题: 由于缺少指数,这一过程每半年进行一次。
教养: 检查指数和编制数据的程序 调查表和删除指数的程序结束时,采用萨米语法,因为不需要,而是每季度。 展示 这里只有 drop子
-- drop the index
begin
IF EXISTS (SELECT * FROM sys.indexes WHERE name= Index_Name
AND object_id = OBJECT_ID( [SchmaName].[TableName] ))
begin
DROP INDEX [Index_Name] ON [SchmaName].[TableName];
end
end
您提问的隐蔽目的是DROP
在将
DROP INDEX IF EXISTS [IndexName] ON [dbo].[TableName]
该星号自2016年8月5日以来一直可供使用。 文件<代码> EXISTS:
https://blogs.msdn.microsoft.com/sqlserverstorageengine/2015/11/03/drop-if-exists-new-thing-in-ql-server-2016/
如果你处理一件主要事,则使用:
ALTER TABLE [TableName] DROP CONSTRAINT IF EXISTS [PK_name]
然而,与原始问题稍有偏离,可能会证明对希望上岸的今后人们有用,即:CREATE
a index,即部署说明。
仅通过在你的发言中添加以下内容就可以绕过现有的检查:
CREATE INDEX IX_IndexName
ON dbo.TableName
WITH (DROP_EXISTING = ON);
详见:。 CREATE INDEX (Transact-SQL) - DROP_EXISTING Articles
N.B. 正如评论中所提到的,本条款在不出现错误的情况下开展工作,必须具备这一指数。
转而履行以下职能,使我能够迅速检查是否存在指数;只像项目目标。
CREATE FUNCTION INDEX_OBJECT_ID (
@tableName VARCHAR(128),
@indexName VARCHAR(128)
)
RETURNS INT
AS
BEGIN
DECLARE @objectId INT
SELECT @objectId = i.object_id
FROM sys.indexes i
WHERE i.object_id = OBJECT_ID(@tableName)
AND i.name = @indexName
RETURN @objectId
END
GO
EDIT:这只是回到表中的分目标,但如果指数确实存在的话,它将是NUL。 我恳请你将这一指数确定下来,以换取回报指数,但这是多余的。
-- Delete index if exists
IF EXISTS(SELECT TOP 1 1 FROM sys.indexes indexes INNER JOIN sys.objects
objects ON indexes.object_id = objects.object_id WHERE indexes.name
= Your_Index_Name AND objects.name = Your_Table_Name )
BEGIN
PRINT DROP INDEX [Your_Index_Name] ON [dbo].[Your_Table_Name]
DROP INDEX [our_Index_Name] ON [dbo].[Your_Table_Name]
END
GO
EXEC sp_helpindex [[[SCHEMA-NAME.TABLE-NAME]]]
GO
a. 特定表格中是否存在分类指数:
SELECT * FROM SYS.indexes
WHERE index_id = 1 AND name IN (SELECT CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE TABLE_NAME = Table_Name )
I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...
In our database we have an SQL server account that has the correct roles to access some of the databases. We are now switching to windows authentication and I was wondering if we can create a NT user ...
I have been trying to execute a MS SQL Server stored procedure via JDBC today and have been unsuccessful thus far. The stored procedure has 1 input and 1 output parameter. With every combination I ...
Is it possible to use the sqlcmd command to dump table structure the way it can be done with mysqldump?
Hi I have the following SP, however when I use LINQ to SQL it generates 2 multiple recordsets. For my sanity I am trying to fathom out what it is in the stored procedure that is doing this and would ...
I want to create a table in MS SQL Server 2005 to record details of certain system operations. As you can see from the table design below, every column apart from Details is is non nullable. CREATE ...
I love the new DATE datatype in SQL Server 2008, but when I compare a DATE field to a DATETIME field on a linked server (SQL 2005, in this case), like this: DECLARE @MyDate DATE SET @MyDate = CONVERT(...
How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8