Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Convert data type of identity column
Message
De
15/08/2017 03:51:29
 
 
À
14/08/2017 14:07:54
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Dépannage
Divers
Thread ID:
01653255
Message ID:
01653303
Vues:
47
>>Hi all:
>>
>>We are in process of moving data from MySql into Sql Server. Somebody else is actually doing the moving so I can report only on the results.
>>
>>The MySql tables have an AUTOINC field. When this gets moved into SQL Server the data type is BIGINT.
>>
>>We connect VFP to the server with.
>>SQLSTRCONNECT('Driver={SQL Server Native Client 10.0};Server=someserver;Database=mydatabase;Uid=myuser;Pwd=mypwd;app=myapp')
>>
>>The problem is that this driver brings the value down as CHAR(20) rather than as a number.
>>
>>Is there some paramater I can add to the connection string that would allow converting a BIGINT to a VFP Int value? I'm pretty sure there is some such option in the MySql driver but I can't find it for Sql Server.
>>
>>Failing that, is there some way I can convert all the BIGINT fields to INT after the data has been imported? I've found that I can manually use the table designer to make the change and our utilities for adding records will respect the identity column.
>>
>>But it sure would be easier to run a script to do that for me. All my attempts have run afoul of some constraint condition.
>>
>>Any suggestions?
>>
>>Thanks to all .............. Rich
>
>Thanks Greg and Tom for your replies. Maybe I wasn't clear enough as to what I am looking for.
>
>We have a substantial number of MySql tables that need to be ported into SQL Server. The MySql Workbench utility we used automatically creates AutoInc fields as UnSigned Integers.
>We used a SQL Server Import/Export tool copy these tables. This utility converted the Unsigned Integer into BigInt.
>
>When SQLEXEC() is used to retrieve these BigInt fields from SQL Server, they get converted into Char(20). I know why this happens. I need a way around it.
>
>In MYSQL we add OPTION = 16384 (Treat BIGINT columns as INT columns) to the SQLSTRINGCONNECT() command so this has not been a problem for us.
>Is there an equivalent option in any the SQL Server Native Client 10.0 driver? I haven't been able to find one - but that doesn't necessarily mean it doesn't exist.
>
>We are looking into ways to make the conversion happen during the Export/Import routine but, so far, everything we've seen looks as if it needs to be applied to each table individually.
>If we find a way to make the conversion during the Export/Import process, we'll use it.
>
>Failing that, is there an ALTER command which can change a BIGINT field to an INT field? My attempts to do so ran into errors but, again, that doesn't necessarily mean it can't be done.
>
>Thanks again ................ Rich

(1) I don't see any problem if the BIGINT get converted to char(20). It's sql server anyway that assigns a value to it. FoxPro side does not have to change the content of that field - only use it
(2) If you alter the field in MySQL to an Int instead of in Unsiged - you will have Int fields in sql server and Int field in FoxPro
The reason MySQL unsinged Int gets converted to BigInt is because sql server does not have unsigned int



There is no possibility in the connection string ( https://docs.microsoft.com/en-us/sql/relational-databases/native-client/applications/using-connection-string-keywords-with-sql-server-native-client )
to convert BIGINT To INT and if there were that would be a bug. You cannot fit a BIGINT - and not even an unsigned int - in an INT field
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform