Code Column Read Only Issue in Master Data Services 2016 - sql-server-2016

I have an issue in Master Data Services 2016 my Question is.
Our Client wants to see the Code Column in Excel but he is saying that he couldn't Insert or update the Code Value itself in excel . To fulfil his requirement I set the Code value automatically generated and Read Only. But when I set Code Column read Only then MDS is not allowing us to insert new record .

If a business user wants to insert and update codes, they can't be automatically generated. It's the same as an IDENTITY property in a SQL Server table.
If they have problems updating code values because they were already used, it's because code values are soft-deleted. In that case you need to purge them.
Pre-SQL Server 2016: https://www.mssqltips.com/sqlservertip/3646/purging-entity-members-in-sql-server-master-data-services/
SQL Server 2016 and later: https://www.mssqltips.com/sqlservertip/4588/purge-an-entity-in-master-data-services-2016/

Related

Migrating legacy data from SQL Server 2000 to 2019 , log block error - is there a painless way of moving over tables with autoinc identity columns? [migrated]

This question was migrated from Stack Overflow because it can be answered on Database Administrators Stack Exchange.
Migrated 5 days ago.
I've been tasked with migrating data from an instance of SQL Server 2000 to 2019. There are a total of four databases to bring over, three of which I was able to backup/restore into 2008 and then into 2019 without any issues. Please note: I am not a DBA in any sense, though I'm the closest thing to one on hand.
The fourth and final database presented the following error that prevented moving from 2008 to 2019:
System.Data.SqlClient.SqlError: An error occurred while processing the log for database 'DbNameHere'. The log block version 2 is unsupported. This server supports log version 3 to 6. (Microsoft.SqlServer.SmoExtended)
Is there a simple fix for this problem that I'm missing in the various SSMS menus?
Alternatively, is there a way to copy raw data from one server to another via, for instance, a flat file, and preserve the identity columns as identity columns? That is, I don't want to just strip that column and bulk insert, as they are often used as foreign keys in other tables, and with twenty-some-odd years of data, something is bound to break in doing this.
An example of an ideal final result in this solution would be something like: legacy table X has 1000 rows, the last of which has an identity column value of 1000. Once the move is complete, new table X has 1000 rows, the last of which has an identity column value of 1000, and upon insert the next row automatically increments to 1001.
Apart from unsuccessfully messing around with flat files, I've also tried the "Copy Database" option in SSMS, which also failed.
I would attempt to get SQL Server to rebuild the transaction log. Based on the error message, that might sort out the situation.
You first use sp_detach_db to detach the database. It is now very likely that the ldf file isn't needed when you do a subsequent attach, and perhaps rebuilding the log this way will sort the situation.
Then you attach the database, without the ldf file. Use CREATE DATABASE with either of the FOR ATTACH or FOR ATTACH_REBUILD_LOG options.
I would do this on the 2008 instance, since from what I understand you got the database in there successfully. But feel free to play around regarding on which version (2000 or 2008) you do the detach and also on which version (2000, 2008, 2019) you do the attach.

SQL Server update two different server by trigger

I have two SQL Server
1st - 10.101.102.133
2nd - 10.101.102.155
Both having the different database with different names and fields.
My application will update in the 1st server.
Can I actually configure the 1st server that once it received update query, it will update in 2nd server as well?
I want to insert data from 1st server to 2nd server by using trigger. when my Application insert data in a table in 1st server database a trigger will fire (insert trigger). and it pass the data in 2nd server by its user id and password.
How I write the script of this trigger?
Solved here: Selecting data from two different servers in SQL Server
You can use sp_addlinkedserver or Linked Servers approach.
Using sp_addlinkedserver would be something like this once you have set up the linked server:
select
*
from
LocalTable,
[OtherServerName].[OtherDB].[dbo].[OtherTable]

Import Excel Spreadsheet Data to an EXISTING sql table?

I have a table called tblAccounts whose contents will come from an excel spreadsheet.
I am using MS SQL Server 2008 (x64) on a Windows 8.1 (x64)
I tried using the SQL Server Import/Export Wizard but there is no option to choose an existing table but only an option to create a new one.
I tried using other methods such as OPENROWSETS
INSERT INTO tblAccount SELECT * FROM OPENROWSET( 'Microsoft.Jet.OLEDB.4.0',
'Excel 12.0;Database=D:\exceloutp.xls','SELECT * FROM [Sheet1$]')
but gave me an error:
Msg 7308, Level 16, State 1, Line 1
OLE DB provider 'Microsoft.Jet.OLEDB.4.0' cannot be used for distributed queries because the provider is configured to run in single-threaded apartment mode.
Some research told me that it occurred because of a 64-bit instance of SQL server.
The problem is that this Excel data transfer to a SQL table must be accomplished using the SQL Import/Export Wizard only.
How can I import an Excel spreadsheet to an existing SQL table without creating a new one?
Some links I visited but was not able to help me resolve my problem:
How do I import an excel spreadsheet into SQL Server?
Fix OLE DB error
You can copy-paste data from en excel-sheet to an SQL-table by doing so:
Select the data in Excel and press Ctrl + C
In SQL Server Management Studio right click the table and choose Edit Top 200 Rows
Scroll to the bottom and select the entire empty row by clicking on the row header
Paste the data by pressing Ctrl + V
Note: Often tables have a first column which is an ID-column with an auto generated/incremented ID. When you paste your data it will start inserting the leftmost selected column in Excel into the leftmost column in SSMS thus inserting data into the ID-column. To avoid that keep an empty column at the leftmost part of your selection in order to skip that column in SSMS. That will result in SSMS inserting the default data which is the auto generated ID.
Furthermore you can skip other columns by having empty columns at the same ordinal positions in the Excel sheet selection as those columns to be skipped. That will make SSMS insert the default value (or NULL where no default value is specified).
Saudate, I ran across this looking for a different problem. You most definitely can use the Sql Server Import wizard to import data into a new table. Of course, you do not wish to leave that table in the database, so my suggesting is that you import into a new table, then script the data in query manager to insert into the existing table. You can add a line to drop the temp table created by the import wizard as the last step upon successful completion of the script.
I believe your original issue is in fact related to Sql Server 64 bit and is due to your having a 32 bit Excel and these drivers don't play well together. I did run into a very similar issue when first using 64 bit excel.
You can use import data with wizard and there you can choose destination table.
Run the wizard. In selecting source tables and views window you see two parts. Source and Destination.
Click on the field under Destination part to open the drop down and select you destination table and edit its mappings if needed.
EDIT
Merely typing the name of the table does not work. It appears that the name of the table must include the schema (dbo) and possibly brackets. Note the dropdown on the right hand side of the text field.
If you would like a software tool to do this, you might like to check out this step-by-step guide:
"How to Validate and Import Excel spreadsheet to SQL Server database"
http://leansoftware.net/forum/en-us/help/excel-database-tasks/worked-examples/how-to-import-excel-spreadsheet-to-sql-server-data.aspx

Office side automation from SSIS

PLease help me out.
I am currently migrating DTS 2000 packages to SQL 2005 version. I have a package which has a VB script in it. The job of this VB script is to download data from AVAYA server and update some templates. Post which it will select specific cells in the excel templates and update some more templates and run a stored procedure to further update a table.
I know that this can be replaced by SSIS scripting. But I have come to know that office side automation is not recomended anymore from SQL server.
So what is the best possible solution. This is a strict requirement that I update those excel templates from SSIS.
I saw this question over on dba.SE and it seemed an interesting approach. By installing the ACE OLEDB driver, not a full blown Office install, you can use any of your familiar DML (INSERT, UPDATE, DELETE) statements to modify values in Excel. I've used this approach to query Excel like a table before but never thought to try to modify the contents.
After installing the driver, you simply create an OLE DB Connection to the Excel resource and then use an Execute SQL Task to fire off your updates. Syntax to add the value DOB to cell D2 on Sheet1 would be
INSERT INTO [Sheet1$D2:D2] VALUES ('DOB')
Other examples from the wordpress article
INSERT INTO [NameOfExcelSheet] VALUES('firsttextcol', 2, '4/11/2009');
-- [I assume First Column is char field, 2nd col is integer, 3rd is Date]
DELETE FROM [NameOfExcelSheet] Where secondintcol=2;
UPDATE [NameOfExcelSheet] SET secondintcol = 3 where firsttextcol = ‘firsttextcol’;
References
http://www.winautomation.com/forum/updating-excel-through-sql-statement
http://yoursandmyideas.wordpress.com/2011/02/05/how-to-read-or-write-excel-file-using-ace-oledb-data-provider/
http://bidn.com/blogs/KeithHyer/bidn-blog/2475/updating-a-single-excel-cell-using-ssis

SQL Server 2008 R2 Data Export Problems

I am trying to export data from my production DB to my development DB but I am getting this error:
Messages Error 0xc0202049: Data Flow Task 1: Failure inserting into the
read-only column "id". (SQL Server Import and Export Wizard)
Is there a way to check which column is that because I have 20 tables that all of them use the column name id or at least get a better error report?
Just click on Edit mappings when you choose tables to import from and to. and check on the Enable identity insert checkbox. And you should do that for each choosen table. Then you can complete your import. It was helped me in the same situation.
If the column ID is an identity column, it's likely set up to generate automatically when a row is inserted, and is not able to be directly written to.
To preserve linking from the production environment to the test, use:
SET Identity_Insert <TableName> ON
To allow you to write identity values.
All I had to do was:
Right-click on the column (in this case 'ID')
Select Modify
Inside the Column Properties scroll down until you see Identity Specification
Expand the view and select NO from the drop down menu.
If anyone knows a different (faster) way of doing this please share
Sounds to me as though you might be trying to insert values into a column that has been declared as an IDENTITY field.
Well, the answer is a bit late but I'm posting it anyway for the sake of providing to community.
I assume that you are trying to copy tables (not partial data). My answer is based on this assumption.
Connect to the source db via Object Explorer in SSMS.
Right click the db that you want its tables to be copied.
Go to 'Tasks' --> 'Export'.
Choose your source and destination server and if you don't want additional script to be run before hands just press next ('Copy data from one or more tables or views'). Now you may select tables you want to be copied to the destination.
Select tables that you want to be completely copied to the destination. And click on 'edit mappings'. Here you may 'enable identity insert'. You will also have other options so check the screen before pressing OK.
If you do not use an express edition of SSMS here you may create an SSIS package to create jobs and to automatize this process in the future. You may check 'run immediately' and follow the screen about how it goes with all the warnings and errors. Hopefully you will get none. Good luck!
Tested with:
(
Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (Intel X86)
Jun 17 2011 00:57:23
Copyright (c) Microsoft Corporation
Enterprise Edition on Windows NT 5.2 <X86> (Build 3790: Service Pack 2)
)