SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Query Analyzer Extended


Query Analyzer Extended

Author
Message
yakov shlafman-248344
yakov shlafman-248344
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: 1

Hi Alan,

I will post a new, inproved version of the proc with

identity property.

Thanks

Regards

Yakov


Yakov Shlafman
Yakov Shlafman
Mr or Mrs. 500
Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)

Group: General Forum Members
Points: 561 Visits: 516

Hi Vernon,

Kalen Delaney wrote an exellent article "User-Defined Data Types" http://www.windowsitpro.com/SQLServer/Article/ArticleID/37427/37427.html.

She provides a stored procedure that shows all user defined datatypes.

Please let me know it this answers all your questions.

Thanks

Regard

Yakov


Yakov Shlafman
Yakov Shlafman
Mr or Mrs. 500
Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)

Group: General Forum Members
Points: 561 Visits: 516

Hi Alan,

now the new, inproved version of the proc with

identity property is available from the same link. Format 1, type 1.

Thanks

Regards

Yakov


EX Gianluca Sartori
EX Gianluca Sartori
Forum Newbie
Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)

Group: General Forum Members
Points: 8 Visits: 8

Hi everybody,

I don't like short names for stored procedures, I prefer to know exactly what a sp is going to do just by looking at its name rather than having to open it and read the code. I'm a Java developer and I'm quite used to dealing with long named functions and methods...

By the way, I see no need for a sp to get table columns information, since I can query INFORMATION_SCHEMA.COLUMNS. If I have to generate code for a statement, I do it querying INFORMATION_SCHEMA, but it must be worth the while: I will never do it for a simple select / insert statement, since it is so easy and strightforward to write sql statements that it would take me much longer to remember the sp name rather than writing the statement by myself.

Regards

Gianluca Sartori


Ram Ram
Ram Ram
SSC Veteran
SSC Veteran (261 reputation)SSC Veteran (261 reputation)SSC Veteran (261 reputation)SSC Veteran (261 reputation)SSC Veteran (261 reputation)SSC Veteran (261 reputation)SSC Veteran (261 reputation)SSC Veteran (261 reputation)

Group: General Forum Members
Points: 261 Visits: 452

May be just give a try.

USE NorthWind
GO

DECLARE @tblName VARCHAR(35)
SELECT @tblName = 'Products'

SELECT [DeclareStmt] = RTRIM('DECLARE @'+C.[Name]+SPACE(CharLen-LEN(C.[Name]))+CHAR(9)
+CASE WHEN T.[Name] IN ('SMALLDATETIME','DATATIME','TEXT','IMAGE','BIT','NTEXT','UNIQUEIDENTIFIER',
'BIGINT','INT','SMALLINT','TINYINT','MONEY','SMALLMONEY')
THEN UPPER(T.[Name])
WHEN T.[Name] IN ('DECIMAL','NUMERIC')
THEN UPPER(T.[Name]) + + '(' + CAST(C.[Length] AS VARCHAR(255)) + ') [' + CAST(C.[XPrec] AS VARCHAR(255))
+ ',' + CAST(C.[XScale] AS VARCHAR(255)) + ']'
ELSE UPPER(T.[Name]) + '(' + CAST(C.[Length] AS VARCHAR(255)) + ')'
END),
[InsertStmt] = RTRIM(QUOTENAME(C.[Name],'[]')+CASE WHEN C.ColId <> MaxLen.CId THEN ',' ELSE '' END),
[ValuesStmt] = RTRIM('@'+C.[Name]+CASE WHEN C.ColId <> MaxLen.CId THEN ',' ELSE '' END),
[UpdateStmt] = RTRIM(QUOTENAME(C.[Name],'[]')+SPACE(CharLen-LEN(C.[Name]))+CHAR(9)+' = @'+C.[Name]
+CASE WHEN C.ColId <> MaxLen.CId THEN ',' ELSE '' END),
[AssignStmt] = RTRIM('@'+C.[Name]+SPACE(CharLen-LEN(C.[Name]))+CHAR(9)+' = '+QUOTENAME(C.[Name],'[]')+
CASE WHEN C.ColId <> MaxLen.CId THEN ',' ELSE '' END),
[DefaultValue] = SC.[Text],
[ConstName] = Obj.[Name],
Nullable = CASE WHEN C.[IsNullable] = 1 THEN 'Y' ELSE 'N' END,
IsIdentity = CASE WHEN C.[Status]&0x80 = 0x80 THEN 'Y' ELSE 'N' END,
[ProcParams] = RTRIM('@'+C.[Name]+SPACE(CharLen-LEN(C.[Name]))+CHAR(9)
+CASE WHEN T.[Name] IN ('SMALLDATETIME','DATATIME','TEXT','IMAGE','BIT','NTEXT','UNIQUEIDENTIFIER',
'BIGINT','INT','SMALLINT','TINYINT','MONEY','SMALLMONEY')
THEN UPPER(T.[Name])
WHEN T.[Name] IN ('DECIMAL','NUMERIC')
THEN UPPER(T.[Name]) + + '(' + CAST(C.[Length] AS VARCHAR(255)) + ') [' + CAST(C.[XPrec] AS VARCHAR(255))
+ ',' + CAST(C.[XScale] AS VARCHAR(255)) + ']'
ELSE UPPER(T.[Name]) + '(' + CAST(C.[Length] AS VARCHAR(255))+')'
END)+SPACE((16-LEN(CASE WHEN T.[Name] IN ('SMALLDATETIME','DATATIME','TEXT','IMAGE','BIT','NTEXT','UNIQUEIDENTIFIER',
'BIGINT','INT','SMALLINT','TINYINT','MONEY','SMALLMONEY')
THEN UPPER(T.[Name])
WHEN T.[Name] IN ('DECIMAL','NUMERIC')
THEN UPPER(T.[Name]) + + '(' + CAST(C.[Length] AS VARCHAR(255)) + ') [' + CAST(C.[XPrec] AS VARCHAR(255))
+ ',' + CAST(C.[XScale] AS VARCHAR(255)) + ']'
ELSE UPPER(T.[Name]) + '(' + CAST(C.[Length] AS VARCHAR(255)) + ')'
END))+1)+CHAR(9)+CASE WHEN C.[IsNullable] = 1 THEN '= NULL' ELSE '' END+CASE WHEN C.ColId <> MaxLen.CId THEN ',' ELSE '' END
FROM dbo.SysObjects AS O
INNER JOIN dbo.SysColumns AS C
ON O.[Id] = C.[Id]
INNER JOIN dbo.SysTypes AS T
ON C.[XType] = T.[XType]
AND T.[XType] = T.[XUserType]
INNER JOIN (SELECT [Id],MAX(LEN([Name]))+1 AS CharLen,MAX(ColId) AS CId FROM dbo.SysColumns GROUP BY [Id]) AS MaxLen
ON MaxLen.[Id] = C.[Id]
LEFT OUTER JOIN dbo.SysComments AS SC
ON C.[CDefault] = SC.[Id]
AND SC.[ColId] = 1
LEFT JOIN dbo.SysObjects AS Obj
ON SC.[Id] = Obj.[Id]
WHERE O.[Name] = @tblName
AND O.XType IN ('U','V')
ORDER BY O.[Name],C.[ColId],C.[ColOrder]

Ram


Ram Ram
Ram Ram
SSC Veteran
SSC Veteran (261 reputation)SSC Veteran (261 reputation)SSC Veteran (261 reputation)SSC Veteran (261 reputation)SSC Veteran (261 reputation)SSC Veteran (261 reputation)SSC Veteran (261 reputation)SSC Veteran (261 reputation)

Group: General Forum Members
Points: 261 Visits: 452

May be just give a try.

USE NorthWind
GO

DECLARE @tblName VARCHAR(35)
SELECT @tblName = 'Products'

SELECT [DeclareStmt] = RTRIM('DECLARE @'+C.[Name]+SPACE(CharLen-LEN(C.[Name]))+CHAR(9)
+CASE WHEN T.[Name] IN ('SMALLDATETIME','DATATIME','TEXT','IMAGE','BIT','NTEXT','UNIQUEIDENTIFIER',
'BIGINT','INT','SMALLINT','TINYINT','MONEY','SMALLMONEY')
THEN UPPER(T.[Name])
WHEN T.[Name] IN ('DECIMAL','NUMERIC')
THEN UPPER(T.[Name]) + + '(' + CAST(C.[Length] AS VARCHAR(255)) + ') [' + CAST(C.[XPrec] AS VARCHAR(255))
+ ',' + CAST(C.[XScale] AS VARCHAR(255)) + ']'
ELSE UPPER(T.[Name]) + '(' + CAST(C.[Length] AS VARCHAR(255)) + ')'
END),
[InsertStmt] = RTRIM(QUOTENAME(C.[Name],'[]')+CASE WHEN C.ColId <> MaxLen.CId THEN ',' ELSE '' END),
[ValuesStmt] = RTRIM('@'+C.[Name]+CASE WHEN C.ColId <> MaxLen.CId THEN ',' ELSE '' END),
[UpdateStmt] = RTRIM(QUOTENAME(C.[Name],'[]')+SPACE(CharLen-LEN(C.[Name]))+CHAR(9)+' = @'+C.[Name]
+CASE WHEN C.ColId <> MaxLen.CId THEN ',' ELSE '' END),
[AssignStmt] = RTRIM('@'+C.[Name]+SPACE(CharLen-LEN(C.[Name]))+CHAR(9)+' = '+QUOTENAME(C.[Name],'[]')+
CASE WHEN C.ColId <> MaxLen.CId THEN ',' ELSE '' END),
[DefaultValue] = SC.[Text],
[ConstName] = Obj.[Name],
Nullable = CASE WHEN C.[IsNullable] = 1 THEN 'Y' ELSE 'N' END,
IsIdentity = CASE WHEN C.[Status]&0x80 = 0x80 THEN 'Y' ELSE 'N' END,
[ProcParams] = RTRIM('@'+C.[Name]+SPACE(CharLen-LEN(C.[Name]))+CHAR(9)
+CASE WHEN T.[Name] IN ('SMALLDATETIME','DATATIME','TEXT','IMAGE','BIT','NTEXT','UNIQUEIDENTIFIER',
'BIGINT','INT','SMALLINT','TINYINT','MONEY','SMALLMONEY')
THEN UPPER(T.[Name])
WHEN T.[Name] IN ('DECIMAL','NUMERIC')
THEN UPPER(T.[Name]) + + '(' + CAST(C.[Length] AS VARCHAR(255)) + ') [' + CAST(C.[XPrec] AS VARCHAR(255))
+ ',' + CAST(C.[XScale] AS VARCHAR(255)) + ']'
ELSE UPPER(T.[Name]) + '(' + CAST(C.[Length] AS VARCHAR(255))+')'
END)+SPACE((16-LEN(CASE WHEN T.[Name] IN ('SMALLDATETIME','DATATIME','TEXT','IMAGE','BIT','NTEXT','UNIQUEIDENTIFIER',
'BIGINT','INT','SMALLINT','TINYINT','MONEY','SMALLMONEY')
THEN UPPER(T.[Name])
WHEN T.[Name] IN ('DECIMAL','NUMERIC')
THEN UPPER(T.[Name]) + + '(' + CAST(C.[Length] AS VARCHAR(255)) + ') [' + CAST(C.[XPrec] AS VARCHAR(255))
+ ',' + CAST(C.[XScale] AS VARCHAR(255)) + ']'
ELSE UPPER(T.[Name]) + '(' + CAST(C.[Length] AS VARCHAR(255)) + ')'
END))+1)+CHAR(9)+CASE WHEN C.[IsNullable] = 1 THEN '= NULL' ELSE '' END+CASE WHEN C.ColId <> MaxLen.CId THEN ',' ELSE '' END
FROM dbo.SysObjects AS O
INNER JOIN dbo.SysColumns AS C
ON O.[Id] = C.[Id]
INNER JOIN dbo.SysTypes AS T
ON C.[XType] = T.[XType]
AND T.[XType] = T.[XUserType]
INNER JOIN (SELECT [Id],MAX(LEN([Name]))+1 AS CharLen,MAX(ColId) AS CId FROM dbo.SysColumns GROUP BY [Id]) AS MaxLen
ON MaxLen.[Id] = C.[Id]
LEFT OUTER JOIN dbo.SysComments AS SC
ON C.[CDefault] = SC.[Id]
AND SC.[ColId] = 1
LEFT JOIN dbo.SysObjects AS Obj
ON SC.[Id] = Obj.[Id]
WHERE O.[Name] = @tblName
AND O.XType IN ('U','V')
ORDER BY O.[Name],C.[ColId],C.[ColOrder]

Ram


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