SQL to insert new contact into Microsoft CRM

It's not supported by Microsoft to directly update/insert data in Microsoft CRM using SQL. So if you use this code you must consider the pros and cons.

Declare @GUID as uniqueidentifier


Declare @AddressGUID as uniqueidentifier

Set @AddressGUID=NEWID()

--NOTE: the guids you see in this sql for owningbusinessunit, ownerid, createdby, modifiedby and TransactionCurrencyID are values that we lifted from an existing record in Microsoft CRM

insert into Test_MSCRM.dbo.ContactBase (contactId, LastName, FirstName, Fullname, statecode, ownerid, OwningBusinessUnit, CreatedBy, createdon, ModifiedOn, ModifiedBy, TransactionCurrencyId)

values (@GUID, 'Johnson','Devin', 'Devin Johnson', '0', '7C0EAC14-0284-E111-942D-00155D017404','20BA18D3-F383-E111-A325-00155D017404','7C0EAC14-0284-E111-942D-00155D017404', GETDATE(),

GETDATE(), '7C0EAC14-0284-E111-942D-00155D017404', '6E00433B-F483-E111-A325-00155D017404'


--Note: this next table is for any user defined fields you have created

insert into Test_MSCRM.dbo.ContactExtensionBase (ContactId, new_CIFNumber) values (@GUID, '9999999')

insert into Test_MSCRM.dbo.CustomerAddressBase (ParentId, CustomerAddressId, AddressNumber, objecttypecode, Line3, City, StateOrProvince, PostalCode, CreatedBy, CreatedOn, ModifiedBy, ModifiedOn)

values (@GUID, @AddressGUID,'1', '2', '1400 Simms, Suite 240', 'Lakewood', 'CO', '80401',

'7C0EAC14-0284-E111-942D-00155D017404', GETDATE(), '7C0EAC14-0284-E111-942D-00155D017404', GETDATE())