--TSQL SNIPPET FOR LISTING TABLE COLUMNS AS LIST FOR SELECT , UPDATE INSERT STATEMENTS
set nocount off;
--SEARCH FOR A TABLE WHICH HAS "TableName" IN ITS NAME
select name AS 'TABLE_NAME'from sys.tables where name like '%TableNa%'
--PRINT THE COLUMNS OF THIS TABLE
DECLARE @ColName varchar(100)
DECLARE @cursorColNames CURSOR
SET @cursorColNames = CURSOR FOR
select column_name from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME ='TableName'
OPEN @cursorColNames
FETCH NEXT
FROM @cursorColNames INTO @ColName
WHILE @@FETCH_STATUS = 0
BEGIN
--set nocount off;
print '[' + @ColName + '],'
FETCH NEXT
FROM @cursorColNames INTO @ColName
END
CLOSE @cursorColNames
select @@error
No comments:
Post a Comment
- the first minus - Comments have to be moderated because of the spammers
- the second minus - I am very lazy at moderating comments ... hardly find time ...
- the third minus - Short links are no good for security ...
- The REAL PLUS : Any critic and positive feedback is better than none, so your comments will be published sooner or later !!!!