Microsoft SQL resetting ID auto increment - mysql

I am using Microsoft SQL server 2012 and i am trying to reset my table primary key IDs so its in a sequential manner, i know some will say its better to leave it as it is but i just want to find out a way to do it.
Question edited due to extra knowledge gained within the first 10mins of post

This is the command to use in SQL Server 2008, and should be the same for 2012:
Reset autoincrement in Microsoft SQL Server 2008 R2
DBCC CHECKIDENT ("YourTableNameHere", RESEED, 1);
And it's not very clear if you want it in MySQL or T-SQL syntax.

Related

Insert Into using Microsoft SQL Server 2008 R2

I am tryng to insert a new user into a simple table that contains ID and Name.
This is the query that I execute:
INSERT INTO [dKArchive].[dbo].[Logins]
([IDL]
,[Name])
VALUES
(37
,'pippo.paperino')
GO
I am using Microsoft SQL Server Management Studio.
After executing query, the value is added in the table, after when I close the Microsoft SQL Server Management Studio and reopen it, this data disappears.
Why does it happen?
Thanks. Best regards.
Second attempt at answering:
SSMS has an option to set that every query is a transaction. You find this under
Tools...->Options->Query Execution->SQL Server->ANSI->SET IMPLICIT_TRANSACTION
If this option is on, you will get something close to the behaviour you describe. However, when closing SSMS, you will get a warning about uncommitted transactions. Ignoring this warning is not a good idea.
At that time, you can click Commit and all is well, or you can just turn off this option.

Prevent sql server Compact as a subscriber to anonymous merge pull publication

Is there a way to specify as a property to my publication, to say it doesn't need to handle sql compact subscriptions?
Sql server 2008 R2 as the publisher, when I originally created the publication, I set the compatibility to 2005 and up. I unknowingly used a time column in one of the replicated articles, and realized after it is too late that for sql ce, it comes down as nvarchar.
First of all, time datatype is introduced from 2008, so I changed my publication compatibility to 2008. And createad new snapshot, reinitialized subscriptions etc.
Currently all my subscibers are 2008 express. I will never need to handle 2005 subscribers.
Also, I never need to handle 2008 Compact subscribers. since time is not supported only for compact, my theory is, if I can somehow specify that the publication need not allow compact subscribers and regenerate my snapshot and redo subscriptions, that column will finally come down as 'time' instead of nvarchar.
So, is it a possibility?
EDIT:
I overlooked the fact that there is no such thing as 'sql server 2008 compact'. I guess my question now is, after I created a pubication with 'subscriber types' as 2005 and up, and later after atleast one subscriber exists(only 2008 express), I change the publication property to 2008 and up, why doesn't any new subscibers get 'time' datatype? Can someone assure that if I totally delete the publication and recreate it from scratch, subscriptions will get the 'time' column fine?
The "New Publication Wizard" has a "Subscriber Types" dialog, on this, select only SQL Server 2008.

MySQL trigger to update SQL Server table

Is it possible to update a table in SQL Server using a trigger in MySQL. The scenario is like this.
When a table is updated in MySQL, a corresponding update is to be done in SQL Server for the purpose of syncing certain fields. I understand that the reverse is possible using a linked server in SQL Server.
You can write a UDF function that would update data in the SQL Server. Then call this UDF from the trigger.
Here's some information which may be of help regarding linking SQL Server and MySQL
http://forums.mysql.com/read.php?60,123221,123221
I'm afraid I've no personal experience in the matter as I thankfully have MySQL servers across the board, however had a scan through the links in the above and at least one of them should be able to assist.

Updating records in MYSQL with SSIS

I am writing an SSIS package that has a conditional split from a SQL Server source that splits records to either be updated or inserted into a MYSQL database.
The SQL Server connection has provider .NET Provider for OldDB\SQL Server Native Client 10.0.
The MYSQL connection is a MYSQL ODBC 5.1 ADO.NET connection.
I was thinking about using the OLE DB Command branching off of the conditional split to update records but I connect use this and connect to the MYSQL database.
Does anyone know how to accomplish this task?
I would write to a staging table for updates including the PK and columns to be updated and then execute an UPDATE SQL statement using that table and the table to be updated. The alternative is to use the command for every row and that just doesn't seem to perform that well in my experience - at least compared to a nice fat batch insert and a single update command.
For that matter, I guess you could do without the conditional split altogether, write everything to a staging table and then use an UPDATE and INSERT in SQL back to back.
Probably, the following MSDN blog link might help you. I haven't tried this.
How do I UPDATE and DELETE if I don’t have an OLEDB provider?
The post suggests the following three options.
Script Component
Store the data in a Recordset
Use a custom component (like Merge destination component)
The author also had posted two other articles about MySQL prior to posting the above article.
Connecting to MySQL from SSIS
Writing to a MySQL database from SSIS
Hope that points you in the right direction.

MySQL to SQL Server migration

I have a mysql database full of data which I need to keep but migrate to SQL Server 2008.
I know end to end where the data should go, table to table but I have no idea how to go about moving the data. I've looked around the web but it seems there are 'solutions' which you have to download and run. I'd rather if possible do something myself in terms of writing scripts or code.
Can anyone recommend the best way to do this please?
You have several options here:
On the sql server side, you can set up a connection to your old mysql db using something called a linked server. This will allow you to write sql code for sql server that returns data from the mysql tables. You can use this to build INSERT or SELECT INTO statements.
You can write queries for mysql to export your data as csv, and then use the BULK INSERT features of sql server to efficiently import the csv data.
You can use Sql Server integration services to set move the data over from mysql.
Regardless of which you choose, non-data artifacts like indexes, foreign keys, triggers, stored procedures, and security will have to be moved manually.
Have you tried tool from MSFT called SQL Server Migration Assistance for MySQL ???
https://www.microsoft.com/download/en/details.aspx?id=1495
Try this tutorial it is very easy to perform migration to SQL Server from Mysql and is straightforward as mentioned
http://www.codeproject.com/Articles/29106/Migrate-MySQL-to-Microsoft-SQL-Server
Thanks
You can use the Import/Export Wizard that comes with SQL Server Standard Edition.
Select your 'data source' from MySQL using the ODBC data source. Note: You will need to first install the from ODBC driver for MySQL (ODBC Connector). Then, select your SQL Server destination. Select all tables, and fire it up. You will need to add your primary and foreign keys, and indexes manually.
A bit more automated means would be by using the SQL Server Migration Assistant for MySQL, also free. It has the benefit of recreating the relationships and indexes automatically for you. Probably your best bet.
I did it once, some time ago. First you could couple your mssql server to the mysql server using the odbc mysql connector
http://dev.mysql.com/downloads/connector/
After the connection is made you can write you database procedure as you would if it were two mssql db's. Probably easiest to write some sql batch scripts including a cursor where you run through every every row of a table an decide on a field basis where you will need the field in the future.
example of a cursor: http://www.mssqltips.com/tip.asp?tip=1599
If you decide to go with the cursor, you can play with the parameter to increase performance. I especially remember the FORWARD_ONLY parameter giving a big boost.