Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««34567»»»

Get DDL for any SQL 2005 table Expand / Collapse
Author
Message
Posted Tuesday, October 18, 2011 7:01 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 6:44 AM
Points: 12,905, Visits: 32,158
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1191997
Posted Tuesday, October 18, 2011 7:35 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, October 19, 2011 2:40 AM
Points: 9, 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?
Post #1192038
Posted Tuesday, October 18, 2011 7:43 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 6:44 AM
Points: 12,905, Visits: 32,158
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1192053
Posted Tuesday, October 18, 2011 8:27 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 6:44 AM
Points: 12,905, Visits: 32,158
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1192125
Posted Tuesday, October 18, 2011 8:44 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, October 19, 2011 2:40 AM
Points: 9, 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?
Post #1192157
Posted Tuesday, October 18, 2011 8:59 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, October 19, 2011 2:40 AM
Points: 9, 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
Post #1192169
Posted Tuesday, October 18, 2011 9:13 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 6:44 AM
Points: 12,905, Visits: 32,158
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1192189
Posted Tuesday, October 18, 2011 9:31 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, October 19, 2011 2:40 AM
Points: 9, 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.
Post #1192217
Posted Tuesday, October 18, 2011 9:39 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 6:44 AM
Points: 12,905, Visits: 32,158
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1192232
Posted Tuesday, October 18, 2011 10:01 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 6:44 AM
Points: 12,905, Visits: 32,158
OK updated yet again...same old links but new code.

sp_GetDDLa_Latest.txt (Returns Table)

sp_GetDDL_Latest.txt (Returns varchar(max) )



Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1192272
« Prev Topic | Next Topic »

Add to briefcase «««34567»»»

Permissions Expand / Collapse