Salut,
J'essaye depuis quelques jours d'utiliser BCP pour exporter/impoirter les données d'une table en skippant une colonne mais ça ne marche pas.
Voilà ce que je fais.
Structure des tables dans les deux bases
1 2 3
| id : numeric Not Null
name : nchar30 Null
first_name : nchar30 Null |
Génération d'un fichier format
BCP Test_new.dbo.ZZTest format nul -f C:\SQL2019\Test_Format.fmt -c -T -S localhost\MSSQLSERVER01
Contenu du fichier de format Test_Format.fmt.
1 2 3 4 5
| 14.0
3
1 SQLCHAR 0 41 "\t" 1 ID ""
2 SQLCHAR 0 60 "\t" 2 NAME SQL_Latin1_General_CP1_CI_AS
3 SQLCHAR 0 60 "\r\n" 3 FIRST_NAME SQL_Latin1_General_CP1_CI_AS |
Modification du fichier de format pour ne pas importer la colonne NAME (je mets 0 avant son nom) : Test_Format_Modif.fmt
1 2 3 4 5
| 14.0
3
1 SQLCHAR 0 41 "\t" 1 ID ""
2 SQLCHAR 0 60 "\t" 0 NAME SQL_Latin1_General_CP1_CI_AS
3 SQLCHAR 0 60 "\r\n" 3 FIRST_NAME SQL_Latin1_General_CP1_CI_AS |
Export des données.
BCP [Test_new].[dbo].[ZZTest] out C:\SQL2019\Test_Out.txt -S localhost\MSSQLSERVER01 -T b1000 t"," -c
Contenu du fichier.
1 2 3 4
| 1,DUBOIS ,Pierre
1,DUBOIS ,Pierre
1,DUBOIS ,Pierre
1,DUBOIS ,Pierre |
Import des données en utilisant le fichier de format : KO, 0 rows insérées...
Je précise que si je n'utilise pas le fichier de format, l'Insert est OK.
1 2 3 4 5 6 7
| C:\Users\User>BCP [Test].[dbo].[ZZTest] in C:\SQL2019\Test_Out.txt -f C:\SQL2019\Test_Format_Modif.fmt -S localhost\MSSQLSERVER01 -T -b1000 -t","
Starting copy...
0 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total : 1 |
Voilà, si vous voyez où est le pb, merci de votre aide.
Partager