Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 DOS Rename

Author  Topic 

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-19 : 10:09:27
OK..jammed up

SSMS Now exports to a file per object with filnames (for sprocs) like

dbo.ValidateUser.StoredProcedure.sql

How do I do a rename to lose dbo. and StoredProcedure. from the filename?

Or is there an option in SSMS that I am not aware to just make it sprocname.sql?


And yes I inherited this, and the sproc names have very little in the way of naming standards

Like what does ValidateUser Mean...I'm sure it's a SELECT for existence

so I would have done usp_SEL_User

But we can't just go off renaming things

So before I start checking all of these into PVCS, I'd like to rename them

OH..and some of the sprocs don't even compile



Msg 207, Level 16, State 1, Procedure GetCaseCurrentOwner, Line 19
Invalid column name 'StatusId'.
Msg 207, Level 16, State 1, Procedure GetCaseCurrentOwner, Line 21
Invalid column name 'Id'.
Msg 207, Level 16, State 1, Procedure GetCaseDistributionList, Line 35
Invalid column name 'IsActive'.
Msg 207, Level 16, State 1, Procedure GetCaseDistributionList, Line 57
Invalid column name 'IsActive'.
Msg 209, Level 16, State 1, Procedure GetSecUsersAccess, Line 21
Ambiguous column name 'EffectiveDt'.
Msg 209, Level 16, State 1, Procedure GetSecUsersAccess, Line 22
Ambiguous column name 'EndDt'.
The module 'mntSaveCaseSubType' depends on the missing object 'UpdateMaintenenceListId'. The module will still be created; however, it cannot run successfully until the object exists.
The module 'mntSaveCaseType' depends on the missing object 'UpdateMaintenenceListId'. The module will still be created; however, it cannot run successfully until the object exists.
The module 'mntSaveContactType' depends on the missing object 'UpdateMaintenenceListId'. The module will still be created; however, it cannot run successfully until the object exists.
The module 'mntSaveHairColor' depends on the missing object 'UpdateMaintenenceListId'. The module will still be created; however, it cannot run successfully until the object exists.
The module 'mntSaveLocations' depends on the missing object 'UpdateMaintenenceListId'. The module will still be created; however, it cannot run successfully until the object exists.
The module 'mntSaveQuestion' depends on the missing object 'UpdateMaintenenceListId'. The module will still be created; however, it cannot run successfully until the object exists.
The module 'mntSaveQuestion' depends on the missing object 'UpdateMaintenenceListId'. The module will still be created; however, it cannot run successfully until the object exists.
The module 'mntSaveQuestionEntities' depends on the missing object 'UpdateMaintenenceListId'. The module will still be created; however, it cannot run successfully until the object exists.
The module 'mntSaveRegion' depends on the missing object 'UpdateMaintenenceListId'. The module will still be created; however, it cannot run successfully until the object exists.
The module 'mntSaveSecurityFirms' depends on the missing object 'UpdateMaintenenceListId'. The module will still be created; however, it cannot run successfully until the object exists.
The module 'mntSaveVehicleColors' depends on the missing object 'UpdateMaintenenceListId'. The module will still be created; however, it cannot run successfully until the object exists.
The module 'mntSaveVehicleMake' depends on the missing object 'UpdateMaintenenceListId'. The module will still be created; however, it cannot run successfully until the object exists.
The module 'mntSaveVehicleTypes' depends on the missing object 'UpdateMaintenenceListId'. The module will still be created; however, it cannot run successfully until the object exists.
Msg 207, Level 16, State 1, Procedure SaveDistributionList, Line 40
Invalid column name 'IsActive'.
Msg 207, Level 16, State 1, Procedure SaveDistributionList, Line 45
Invalid column name 'IsActive'.
Msg 207, Level 16, State 1, Procedure SaveDistributionList, Line 44
Invalid column name 'IsActive'.
Msg 207, Level 16, State 1, Procedure SaveDistributionList, Line 55
Invalid column name 'IsActive'.




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


X002548
Not Just a Number

15586 Posts

Posted - 2012-01-19 : 10:27:32
I've tried

rename dbo.*.StoredProcedure.sql *.sql

No luck

pllllllllleeease don't make me have to manually rename hundreds of sprocs

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-01-19 : 11:04:58
Here's some command line magic that might help, run this in your stored procedure directory:

for %z in (dbo.*.sql) do @for /F "tokens=2 delims=." %a in ('echo %z') do @echo ren "%z" "%a.sql"

This will print out the rename commands, I suggest you look them over VERY CAREFULLY before running them. If they look OK, you can perform the rename with this:

for %z in (dbo.*.sql) do @for /F "tokens=2 delims=." %a in ('echo %z') do @ren "%z" "%a.sql"

edit: added quote marks
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-19 : 11:07:35
I'll give it a whirl

I already did this


CREATE TABLE #Dir(Col1 varchar(max))
GO

INSERT INTO #Dir(Col1)
EXEC master..xp_cmdshell 'dir \\L-LLRLTENN\Public\PSRS\Sprocs\*.*'

SELECT CHARINDEX('dbo.',Col1) FROM #Dir



DECLARE myCursor99 cursor
FOR
SELECT 'RENAME \\L-LLRLTENN\Public\PSRS\Sprocs\'
+ SUBSTRING(Col1,40,50) + ' '
+ SUBSTRING(REPLACE(REPLACE(Col1,'dbo.',''),'.StoredProcedure',''),40,50)
FROM #Dir
WHERE CHARINDEX('dbo.',Col1) <> 0

DECLARE @dos varchar(8000)

OPEN myCursor99

FETCH NEXT FROM myCursor99 INTO @dos

WHILE @@FETCH_STATUS = 0
BEGIN
EXEC master..xp_cmdshell @dos
FETCH NEXT FROM myCursor99 INTO @dos
END

CLOSE myCursor99
DEALLOCATE myCursor99
GO

DROP TABLE #Dir
GO





Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2012-01-19 : 12:20:24
I usually do:

DIR /B *.SQL >MyTempFile.BAT

Then use a programmers editor (which allows RegEx style Find & Replace) to change each line from

dbo.ValidateUser.StoredProcedure.sql

to

REN "dbo.ValidateUser.StoredProcedure.sql" "StoredProcedure.sql"

and then run the BATch file.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-19 : 16:36:16
sounds like something I would do on the mainframe...the cursor worked very well



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-01-19 : 18:16:04
Did you try my code at all?
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-20 : 09:01:40
Not yet Rob....After I pushed forward, I had to document how I wanted my team to modify the sprocs...add descriptive headers, log the sproc calls to a table...etc.

I will give it a whirl today



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-01-20 : 10:25:05
erm.

If you right click on the database and then go to Tasks -> Generate Scripts

Then you can export everything to the same file, or multiple files as you wish, you can choose to leave the schema off the names or on.....

basically, everything I think you want to do????

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2012-01-20 : 10:42:32
"you can choose to leave the schema off the names or on"

In the minefield of available options I've never seen that one.

Amazes me that there isn't a means of saving the option choices as a "template" for future script-generations ... although maybe there is and I have just never found it ...
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-01-20 : 10:54:46
quote:

In the minefield of available options I've never seen that one.


It's in the first dialogue. Under general options "Schema qualify object names" by default it's set to true

Yeah -- I can't see a template option either. Which is a pain in the ass.

We use redgate source control and sql compare which means we don't really have to bother with the script tasks too often.

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2012-01-20 : 10:56:57
"Schema qualify object names"

Never realised that that would impact the filenames. Ho!Hum! Thanks for that, filed in memory for longer term use
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-01-20 : 11:04:34
That's all well and good until you use Data Dude. I'm sure there's a way to turn off the naming convention it uses, but it's an even bigger pain in the ass, and it's completely incompatible with the scripts you get from SSMS.

And if you're wondering why I'd use Data Dude, it's because the app includes the database objects in the project, and it's the only way we're allowed to build. It's actually not too bad, it just suffers from new-kid-on-the-block-and-therefore-I'm-better-than-everyone design mentality.
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-01-20 : 11:10:48
you going to shift when you can do everything from visual studio in 2012?

EDIT: Wait, that was what you were talking about right? the stuff that was in the CTP3. Dac packs etc?

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION[/red]
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-20 : 11:32:06
I set that option to false and it still generated the "dbo."

And there was NO option not to generate the ".StoredProcedure" Naming Convention

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-01-20 : 11:37:29
Nope, I wasn't talking about DAC Packs, just Visual Studio Database Projects.
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-01-20 : 11:38:55
hmmm. I dumped everything to one file at the end.

Maybe if you go down the multiple file routes then it just does whatever it pleases.

sorry for the misleading info then.

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page
   

- Advertisement -