Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Get DDL for any SQL 2005 table


Get DDL for any SQL 2005 table

Author
Message
Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14992 Visits: 39023
wierd, gotta be an issue i have not seen;
when i scripted your table and index, i get good, clean results.

can you try the latest sp_GetDDLa to be sure, this is the exact version i used:

sp_GetDDLa_Latest.txt (Returns Table)

sp_GetDDL_Latest.txt (Returns varchar(max) )




CREATE TABLE [dbo].[ACCESS] (
[TEMPFLAG] bit NOT NULL,
[CODE] varchar(50) NOT NULL,
[DESCRIPTN] varchar(50) NOT NULL)

GO

CREATE INDEX [CODE] ON [ACCESS] (CODE) WITH FILLFACTOR = 90



Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

kbleeker
kbleeker
SSC Rookie
SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)

Group: General Forum Members
Points: 27 Visits: 30
Hey again.

I saw in the SP that you insert the data into @Results, so I caught the contents of that - check out the index_name and index_columns_key columns(only 2 rows, since only one index):

index_name -

---
CODE


index_columns_key-

---
CODE,


And there's the magical comma - let me state in no unceratin terms that I'm no SQL ninja, I'm very new to this. It looks to me though that my index columns are being stored somewhere in sys.objects with the commas attached. Does this bring any ideas to mind?
Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14992 Visits: 39023
kbleeker (10/18/2011)
Hey again.

I saw in the SP that you insert the data into @Results, so I caught the contents of that - check out the index_name and index_columns_key columns(only 2 rows, since only one index):

index_name -

---
CODE


index_columns_key-

---
CODE,


And there's the magical comma - let me state in no unceratin terms that I'm no SQL ninja, I'm very new to this. It looks to me though that my index columns are being stored somewhere in sys.objects with the commas attached. Does this bring any ideas to mind?


yeah, that's part of the concatenation of all possible columns...it gets built with FOR XML PATH('') , but later in the query wrapped with this:

SELECT
LEFT(index_columns_key, LEN(index_columns_key)-1) AS index_columns_key,



which takes off the extra comma;

what i suspect is that specific table may have a column named [code ] --notice the space! that might be throwing the scripting off. i'm testing that scenarion now..i might need to quotename() each of the columns in the index to fix it...fast fix if that's the isssue.

Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14992 Visits: 39023
I tweaked both procs to quotename the index column names, and also to replace unix style code to end with vbCrLf;
same links as below, cna you retry by downloading the latest (again)

Lowell (10/18/2011)
wierd, gotta be an issue i have not seen;
when i scripted your table and index, i get good, clean results.

can you try the latest sp_GetDDLa to be sure, this is the exact version i used:

sp_GetDDLa_Latest.txt (Returns Table)

sp_GetDDL_Latest.txt (Returns varchar(max) )



Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

kbleeker
kbleeker
SSC Rookie
SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)

Group: General Forum Members
Points: 27 Visits: 30
I'm sorry to say it, but the result is almost exactly the same:



CREATE TABLE [dbo].[ACCESS] (
[TEMPFLAG] bit NOT NULL DEFAULT (0),
[CODE] varchar(50) NOT NULL,
[DESCRIPTN] varchar(50) NOT NULL)

GO

CREATE INDEX [CODE] ON [ACCESS] ([CODE],) WITH FILLFACTOR = 90



I notice though that the comma is on the outside of the square brackets - does that not remove the column name from the possible problem?
kbleeker
kbleeker
SSC Rookie
SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)

Group: General Forum Members
Points: 27 Visits: 30
Hi Lowell - I made a change which appears to have sorted out the comma, but I'd like to know whether removing the space padding might have som drawback which I haven't foreseen:
I've commented out the space padding between column names in the indexes section, since your LEFT() was only removing one character, AFTER adding the space -

SELECT QUOTENAME(COLS.[name]) + ',' --+ ' '



Thanks,

Kevin
Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14992 Visits: 39023
kbleeker (10/18/2011)
Hi Lowell - I made a change which appears to have sorted out the comma, but I'd like to know whether removing the space padding might have som drawback which I haven't foreseen:
I've commented out the space padding between column names in the indexes section, since your LEFT() was only removing one character, AFTER adding the space -

SELECT QUOTENAME(COLS.[name]) + ',' --+ ' '



Thanks,

Kevin


Kevin you ROCK;
that's it, i think it has to do with whether ANSI_PADDING is on or off.

I was testing some more obscure things to try and recreate the scenario, and found an issue if your database was case Sensitive, the proc would not work, so i fixed that as well as adding the suggestion you identified...same links above, just updated.
mea culpa on the error, should have seen that a long time ago.

Thank you!

Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

kbleeker
kbleeker
SSC Rookie
SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)

Group: General Forum Members
Points: 27 Visits: 30
Haha! Thanks!

Is it okay if I reply with another problem though? (Talk about a trial by fire, this DB is the devil!)

4 columns in this DB are datatype "real", and the sp_GetDDLa is getting column widths for them, which of course leads to:


Cannot specify a column width on data type real.

For the first instance it generated a width of (24) - not sure if this helps, but I'm going through all of the generated scripts now to find the other instances of real, I'll let you know what I find.
Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14992 Visits: 39023
ahh, i had seen that once before...i'll fix that right now.


I can't thank you enough; another pair of eyes, doing work outside of my typical work load and comfort zone helps enourmously.

Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14992 Visits: 39023
OK updated yet again...same old links but new code.

sp_GetDDLa_Latest.txt (Returns Table)

sp_GetDDL_Latest.txt (Returns varchar(max) )

Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search