Posts

Showing posts with the label T-SQL

Updating GDB_Items XML Definitions

First, run a query to identify the feature class "PhysicalName" or UID from GDB_ITEMS. Note: The physical name appears as DBNAME.SCHEMA.FCNAME. Use one of the two for the WHERE clause in the other queries. First Query USE [DBName] SELECT ITEMS.ObjectID ,ITEMS.UUID ,ITEMTYPES.Name as ItemType ,ITEMS.[PhysicalName] ,ITEMS.[Definition] FROM [sde].[GDB_ITEMS] as ITEMS INNER JOIN [sde].[GDB_ITEMTYPES] ITEMTYPES ON [ITEMS].[ Type ] = [ITEMTYPES].[UUID] WHERE [PhysicalName] like '%FC Name%' In the results, click the XML link under the Definition field. You should see something similar to the XML below. Notice the highlighted line of code. This is the "Remarks" field. The node "IsNullable" is set as "false". I want the Remarks field to allow NULL values and would like to update it from "false" to "true". Note: The base and delta tables should be updated as well. XML Definition View <DEFeatu...

Add Field to a SQL Geodatabase using T-SQL

Image
Sometimes a new field will need to be added quickly. The usual process of testing changes and pushing said changes to production is not very time sensitive. Here is a method I use when a new field is needed ASAP. In this case the feature classes have been registered in the geodatabase and archiving has been enabled. This means there is an SDE base table and several SDE delta tables. The information needed to proceed is listed below. This will require DBO level access and SQL Server Management Studio or other suitable RDBMS interface like Toad. Database Name = DemoData New Field Name = NewField New Field Type (Length) = string(50) / nvarchar(50) SDE Field Type Code =   Unknown New Field Name = NewField Feature Class Name = Marker Base Table Name = Marker Base Table ID = Unknown Delta Table (Adds) = Unknown Delta Table (Archive) = Unknown First thing to do is find the unknown values. The SDE Field Type Code via Esri tells us that the SDE Field Type Code for Stri...

Using MS Date Styles for Python

I began scripting with Python to automate nightly routines. After time many of my scripts would include similar variables such as date/time formatting.  For log files I usually apply this format: Sample output: RoutineLog_20150622.log Date Format: yyyymmdd For an email body I usually apply this format: Sample: "The routine succeeded June 22, 2015 02:10PM." Date Format: Mon dd yyyy hh:mm AM/PM Although I tend to apply similar formatting, I noticed different naming conventions as more and more scripts were written. Python Script A would call it datetime while script B called it ShortDate. dateTime1 = time.strftime("%Y%m%d") #yyyymmdd dateTime2 = time.strftime ("%b %d %Y %I:%M%p") I like standards and remembered that Microsoft (MS) has datetime style codes. This is what I now reference when setting date time formatting variables. https://msdn.microsoft.com/en-us/library/ms187928.aspx Although, MS does not account for each and every styl...