Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > SQL Server Defaults


Reply
 
Thread Tools Display Modes
  #1  
Old 03-23-2004, 08:03 AM
SBHang SBHang is offline
Newcomer
 
Join Date: Mar 2004
Posts: 4
Question SQL Server Defaults


Hello,

do anyone know how I can figure out the Defaults on a SQL Server 2000 Database with the current Value of the Default and the Columns that are bounded?

I use VB 6.

Thanks :-)
SBHang
Reply With Quote
  #2  
Old 03-23-2004, 08:48 AM
Andyh Andyh is offline
Junior Contributor
 
Join Date: Feb 2004
Location: Southampton, UK
Posts: 335
Default

You haven't supplied enough info for a concise answer.
"current value" of what default?
which columns are bounded by what?
etc...
Reply With Quote
  #3  
Old 03-23-2004, 08:50 AM
MKoslof's Avatar
MKoslof MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

Do you want to create a table and assign new default values to specific fields, or return any current default values that are already set within your existing fields?
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #4  
Old 03-23-2004, 09:47 AM
SBHang SBHang is offline
Newcomer
 
Join Date: Mar 2004
Posts: 4
Default

Quote:
Originally Posted by MKoslof
Do you want to create a table and assign new default values to specific fields, or return any current default values that are already set within your existing fields?
Ok, sorry.

The Database, the tables and the Defaults already exits, I only want to return the Values and the binded Columns from the Defaults in the SQL Server 2000.

Default -> I know
Values -> I want to know
Binded Columns -> I also want to know

On left side in the Enterprise Manager you see under the Database Diagrams, tables, views, sp's, ... and defaults. When you click on the Defaults tab you see on the right side the current defaults. And I want to return now the Values and the bindend columns.

I hope that explanation will help you, to help me :-)

Thanks :-)
SBHang
Reply With Quote
  #5  
Old 03-23-2004, 09:55 AM
SBHang SBHang is offline
Newcomer
 
Join Date: Mar 2004
Posts: 4
Default

My Code:

Code:
Friend Property Get Defaults() As Scripting.Dictionary
   'Load all Defaults from the syscomments table, only SQL Server!!!
   Dim tmpDic As New Scripting.Dictionary
   Dim DBRecDefaults As ADODB.Recordset
   Set DBRecDefaults = New ADODB.Recordset

   Select Case DatabaseInformation.Item("DBMS Name")
      Case "Microsoft SQL Server"
         DBRecDefaults.Open "SELECT text From syscomments Where (Number = 0) And (colid = 1) And (Status = 2)", DBCon, adOpenStatic, adLockReadOnly
         Set Defaults = LoadDefaults(DBRecDefaults)
      Case "ACCESS"
         Set Defaults = tmpDic
   End Select
   
   Set tmpDic = Nothing
   Set DBRecDefaults = Nothing
End Property
Code:
Private Function LoadDefaults(DBRecDefaults As ADODB.Recordset) As Scripting.Dictionary
   'Edit the Default Data from the syscomments table
   Dim tmpDic As New Scripting.Dictionary
   Dim DataRecord As String
   Dim CutStart As Integer
   Dim CutEnd As Integer
   Dim Item As String
   Dim Key As String
   Dim tmpKey As String
   
   Do Until DBRecDefaults.EOF
      DataRecord = UCase(DBRecDefaults.Fields(0).Value)
      Key = DataRecord
      
      If IsDefault(DataRecord) Then
         CutStart = InStr(DataRecord, "CREATE DEFAULT ") + Len("CREATE DEFAULT ")
         CutEnd = InStr(CutStart, DataRecord, " ")
         If CutEnd < InStr(CutStart, DataRecord, "]") + 1 Then CutEnd = InStr(CutStart, DataRecord, "]") + 1
         
         Item = Mid(DataRecord, CutStart, CutEnd - CutStart)
        
         tmpKey = Item
         Item = Key
         Key = tmpKey
         
         Dim KeyCount As Integer
         Do Until tmpDic.Exists(Key) = False
            KeyCount = KeyCount + 1
            Key = Key + CStr(KeyCount)
         Loop

         tmpDic.Add Key, Item
      End If

      DBRecDefaults.MoveNext
   Loop
   
   
   'Test!!!
   'Set oDefault = oDatabase.Defaults("UnitPrice", "stevenb")
   
   
   
   Set LoadDefaults = tmpDic
   Set tmpDic = Nothing
End Function
With this code I get the names from all Defaults in the current Database on my SQL Server
Reply With Quote
  #6  
Old 03-23-2004, 10:25 AM
Andyh Andyh is offline
Junior Contributor
 
Join Date: Feb 2004
Location: Southampton, UK
Posts: 335
Default

You may need to trawl through the sys... tables in sql server: for example
Code:
 select o.*
from sysobjects o 
where o.name = "defaultname"
gives you the details about one particular default, the following gives you a list of defaults and their attributes:
Code:
 
select o.*
from sysobjects o 
where OBJECTPROPERTY(o.id, N'IsDefault') = 1 
and o.name not like N'#%%' 
and category & 0x0800 = 0  
order by o.name
and the following will give you some attributes of the bindings (if you know the table name:
Code:
 exec sp_MShelpcolumns N'[dbo].[tablename]'
I'll leave the rest for you to find out :-)
Reply With Quote
  #7  
Old 03-24-2004, 02:07 AM
SBHang SBHang is offline
Newcomer
 
Join Date: Mar 2004
Posts: 4
Default

Quote:
Originally Posted by Andyh
You may need to trawl through the sys... tables in sql server: for example
Code:
 select o.*
from sysobjects o 
where o.name = "defaultname"
gives you the details about one particular default, the following gives you a list of defaults and their attributes:
Code:
 
select o.*
from sysobjects o 
where OBJECTPROPERTY(o.id, N'IsDefault') = 1 
and o.name not like N'#%%' 
and category & 0x0800 = 0  
order by o.name
and the following will give you some attributes of the bindings (if you know the table name:
Code:
 exec sp_MShelpcolumns N'[dbo].[tablename]'
I'll leave the rest for you to find out :-)

@All
Thanks

Now I Know, I'm stupid.
I also exported the Value of the Default Key, but I choped it off

Now it works, thanks to all
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Server 6.5 and Jet 4.0 SP8 Bart1123 Database and Reporting 1 03-05-2004 06:54 PM
SQL query pinkcat Database and Reporting 25 02-09-2004 09:36 AM
Creating A New Table In Sql Server grayknight Database and Reporting 4 07-22-2003 07:32 PM
How to connect to SQL server? Angela Database and Reporting 5 06-11-2003 10:09 AM
SQL Server: Please help me get off the ground AnakinVB Database and Reporting 1 08-13-2002 07:56 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->