Is it possible to script multiple queries? I need to transfer about 30 queries from one server to another w/o copying the entire database. I was hoping i wouldn't have to script out each query individually in SSMS.
October 16, 2019 at 4:47 pm
by queries, i am guessing you mean tables, instead.
you can sue the metadata to script out the actual queries by getting the column names, is that what you are after? something like this?
SELECT DISTINCT
t.name,
'SELECT ' + sq.Columns + ' FROM ' + schema_name(t.schema_id) + '.' + t.name
FROM sys.tables t
JOIN (
SELECT OBJECT_ID,
Columns = STUFF((SELECT ',' + name
FROM sys.columns sc
WHERE sc.object_id = s.object_id
FOR XML PATH(''), TYPE).value('.','varchar(max)'),1,1,'')
FROM sys.columns s
) sq ON t.object_id = sq.object_id
WHERE t.name IN(
'Analytics_Locations',
'Analytics_Services',
'Analytics_Campaign',
'Analytics_CampaignAsset'
)
Lowell
October 16, 2019 at 7:41 pm
Is it possible to script multiple queries? I need to transfer about 30 queries from one server to another w/o copying the entire database. I was hoping i wouldn't have to script out each query individually in SSMS.
There is no 'Query' object in a database. What do you mean?
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
October 16, 2019 at 8:03 pm
The only way i know to transfer a query right now is to select each one individually in SSMS and use the Script View As functionality. Is there a way to select more than one query at a time and get a script to create them all at once?
Right-click on the database in SSMS Object Explorer.
Select Tasks/Generate Scripts
Select Views and follow the prompts.
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
October 16, 2019 at 8:29 pm
Crap. I googled it, but didn't search for the right terms apparently. Thanks guys.
October 17, 2019 at 3:52 pm
To add to Phil,
You can also highlight and object in the object explore and then hit F7 to open Object Explorer Details.
Once in the OED you can navigate to folders highlight a group of objects in a folder and right-click to script as. The same is also useful if you wanted to script out all your jobs or be selective with what you want scripted out.
October 17, 2019 at 4:37 pm
To add to Phil,
You can also highlight and object in the object explore and then hit F7 to open Object Explorer Details.
Once in the OED you can navigate to folders highlight a group of objects in a folder and right-click to script as. The same is also useful if you wanted to script out all your jobs or be selective with what you want scripted out.
This also works very well. I can ctrl+click everything and script at one time . Thanks !
October 21, 2019 at 11:44 am
The better option would be to have your database object definitions in your code store, so you can grab them and run them in the new server.
October 21, 2019 at 11:59 am
The better option would be to have your database object definitions in your code store, so you can grab them and run them in the new server.
+1 million to that!!! That would also mean that you have them in some sort of a source control program, which is an imperative so far as I'm concerned.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 21, 2019 at 12:18 pm
Like a visual studio code store?
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply