Option-01: using SYS.COLUMNS
IF EXISTS(SELECT * FROM SYS.COLUMNS WHERE NAME = N'account_id'
AND OBJECT_ID = OBJECT_ID(N'account'))
BEGIN
PRINT 'EXISTS';
END
;
Option-02: using INFORMATION_SCHEMA.COLUMNS
IF EXISTS( SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'account'
AND COLUMN_NAME = 'account_id')
BEGIN
PRINT 'EXISTS';
END
;
IF EXISTS(SELECT * FROM SYS.COLUMNS WHERE NAME = N'account_id'
AND OBJECT_ID = OBJECT_ID(N'account'))
BEGIN
PRINT 'EXISTS';
END
;
Option-02: using INFORMATION_SCHEMA.COLUMNS
IF EXISTS( SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'account'
AND COLUMN_NAME = 'account_id')
BEGIN
PRINT 'EXISTS';
END
;
1 comment:
Greeat blog I enjoyed reading
Post a Comment