开发者

Is it possible to format select asterisk still more?

I have a long table with 75 columns, I am entering test data and it is difficult to enter in the web form

I have already entered a row.

I want to copy it ten times in the table .

Insert into tbl01 
select * from tbl01

code does not work because identity column is on, so I want to do like

开发者_如何学Go
Select * - (column1) from tbl01

I asked my colleague and she told she dont know that such a thing exists.!!!

Note: I dont want to do --

select col1, col2...till col 75


No, you can't do that.

In "Sql Server Management Studio", you can right click a table and select "Script table as" > "Insert to" to generate the column names for you.


You should be able to hack together some dynamic sql with the help of the sys.columns table.

DECLARE @cols varchar(max)

SELECT @cols = coalesce(@cols+',','')+[name]
FROM sys.columns
WHERE object_name(object_ID) = 'tbl01'
    and [name] != 'column1'

DECLARE @query varchar(max)
SELECT @query=replace('insert into ([cols]) select [cols] from tbl01', '[cols]', @cols)

EXECUTE(@query)

Though, to be honest, I'd use this only as another option to the SSMS "Script table as" function. You should really just create a some sql and save it somewhere for reuse.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜