--method 1
IF EXISTS(SELECT 1 FROM sys.columns with (nolock)
WHERE Name = N'LoginName'
AND Object_ID = Object_ID(N'[dbo].[AuditLogin]'))
BEGIN
Print('Column exist')
END
--method 2
IF COL_LENGTH('[dbo].[AuditLogin]','LoginName') IS NOT NULL
BEGIN
PRINT 'Your Column Exists'
END
--method 3
SELECT count(*)
FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME IN ('LoginName')
AND TABLE_SCHEMA='dbo' and TABLE_NAME ='AuditLogin' ;
IF EXISTS(SELECT 1 FROM sys.columns with (nolock)
WHERE Name = N'LoginName'
AND Object_ID = Object_ID(N'[dbo].[AuditLogin]'))
BEGIN
Print('Column exist')
END
--method 2
IF COL_LENGTH('[dbo].[AuditLogin]','LoginName') IS NOT NULL
BEGIN
PRINT 'Your Column Exists'
END
--method 3
SELECT count(*)
FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME IN ('LoginName')
AND TABLE_SCHEMA='dbo' and TABLE_NAME ='AuditLogin' ;
No comments:
Post a Comment