95 How to import a csv file into SQL Server using bulk insert SQL query

Поділитися
Вставка
  • Опубліковано 19 січ 2022
  • How to import a csv file into sql server using bulk insert sql query
    Download the file\script used in the Video from below link
    drive.google.com/drive/folder...
    SSIS Tutorials: • SSIS Tutorials
    SSIS real time scenarios examples: • SSIS real time scenari...
    SSIS Interview questions and answers: • SSIS Interview questio...
    How to import a csv file into sql server using bulk insert sql query
    How do I import a CSV file into SQL Server query?
    How do I import data from Excel to bulk insert in SQL Server?
    How do I import multiple CSV files into SQL Server?
    How import bulk data in SQL Server?
    Happy Learning.
    If you have any questions or suggestions please comment on the video or write to me at “aqil33@gmail.com”
  • Наука та технологія

КОМЕНТАРІ • 56

  • @BoneAppleTea
    @BoneAppleTea Рік тому +2

    Great tutorial, opening it in a textpad is something other tutorials skip. 10/10

  • @peterglover7178
    @peterglover7178 2 роки тому

    Great, simple explanation - thanks for this.

  • @9844468928
    @9844468928 2 роки тому +1

    in an interview they have asked this question and i have struggled a lot to write this simple query. Thank you so much for you help on this Bro

    • @learnssis
      @learnssis  2 роки тому

      No problem. You are most welcome Keerthi.

    • @user-fb1ps9bv9g
      @user-fb1ps9bv9g Рік тому

      Thank you for sharing this, it a tip now

  • @ameet6384
    @ameet6384 2 роки тому

    Awesome worked great!!!
    I was getting some errors while trying to import flat file feature due to large number of records (> 500k).
    The only thing I had to modify here was the file path location. Since my sql server instance was present on a remote sever, I had to use a shared folder path.

    • @learnssis
      @learnssis  2 роки тому

      Nice to hear Ameet that it worked for you.

  • @1321vishal
    @1321vishal Рік тому

    thank you so much sir.

  • @TheMadyam
    @TheMadyam 2 роки тому

    Great video and series. Can you do a video on how to run a SSRS report with a parameter from SSIS and get the report and move to a folder?

    • @learnssis
      @learnssis  2 роки тому

      I have not done this kind of thing as I did not get a chance to work on SSRS reports. Also I don't have SSRS installed on my machine at the moment. Sorry for this.

  • @surajsonawane4270
    @surajsonawane4270 Рік тому +1

    getting an error - Msg 102, Level 15, State 1, Line 9
    Incorrect syntax near 'format'.

  • @gobakos7890
    @gobakos7890 10 місяців тому

    Do you know which tables contains the products in a woocommerce store?also do you have video for XML ?Thanks and you got a sub

    • @learnssis
      @learnssis  10 місяців тому

      Sorry I don't have any information about woocommerce store. I have a video below on loading data from xml file to sql server table using sql query
      ua-cam.com/video/w05oX0obgp4/v-deo.html
      This is how we can import xml file to sql server table using ssis
      ua-cam.com/video/9vWYLGsaXJc/v-deo.html
      And this the method how we can export data from sql server to xml using ssis
      ua-cam.com/video/NuT3CpiUSrM/v-deo.html

  • @hdwallpaper7492
    @hdwallpaper7492 2 роки тому

    nice tutorial ...!! I have diffferent CSV file and throwing me error of (Bulk load data conversion error (type mismatch or invalid character for the specified codepage)) could u please suggest

    • @learnssis
      @learnssis  2 роки тому

      I would suggest you to try using Data Flow task and see if you are able to load it from there.

  • @pratikshashukla6522
    @pratikshashukla6522 2 місяці тому +1

    How to insert a csv file if it contains multiple empty rows ( each column of that row is empty). I want either Bulk insert move to another row if it encounter empty row or it should insert that row with null values.

    • @learnssis
      @learnssis  2 місяці тому

      I think you can handle this using data flow task, that if a column value is empty then it can convert the value to NULL.
      ua-cam.com/video/k7qqrtSY09o/v-deo.html

  • @apeanicaisegneki4200
    @apeanicaisegneki4200 Рік тому

    Thanks Abdul .but I have csv file from kaggle but having difficulties to load data from these csv file into my SQL table using SSIS

    • @learnssis
      @learnssis  Рік тому

      Try using data flow task and if that fails then paste the error here I will try to help
      ua-cam.com/video/aMhwCepVpwE/v-deo.html

  • @rika0729
    @rika0729 5 місяців тому

    whats your current salary... in hand LPA?

  • @sashafroyland
    @sashafroyland Рік тому

    Is using Azure SQL Server, then file needs to be stored on Blog Storage, otherwise it will error out.

    • @learnssis
      @learnssis  Рік тому

      Frankly speaking I never used bulk insert query with Azure, I mostly tried with On-Premises instance.
      I saw some examples online where they use C# to read data from a flat file insert the data to Azure sql server
      stackoverflow.com/questions/46004119/increase-sql-bulk-copy-speed-on-azure
      stackoverflow.com/questions/51686757/bulkcopy-100-million-rows-of-data-to-azure-sql-server-using-c

  • @priyankabachhav5315
    @priyankabachhav5315 10 місяців тому

    Hello sir i want to perform bulk insertion but i am using SQLBindParameter and then SQLBulkOperations for executing but it's giving me error.. I tried finding you on linkdin but not found.. Will you please help me out?

    • @learnssis
      @learnssis  10 місяців тому

      Hi Priyanka, I don't have much experience working with SQLBindParameter and then SQLBulkOperations, 99% of the time I use SSIS to import data from CSV\flat files to sql server table. If you are getting an error then try to google it or you can ask chatgpt as well to see if that can help or you can post your question on stackoverflow.com they give very legitimate answers and they are very quick.

    • @priyankabachhav5315
      @priyankabachhav5315 10 місяців тому

      @@learnssis actually I google it I implemented various ways also, I tried chatgpt but error still arrives.. And also I tried this csv part but it's not taking my folder path accurately.. I am getting error there it's unable to find file. Can we connect and then I will show you?? Maybe you will get to know.. What I am doing wrong

    • @learnssis
      @learnssis  10 місяців тому +1

      @@priyankabachhav5315 Actually I don't have much experience with it thus not sure if I can help you with it, please share the screenshot of the error message and code to aqil33@gmail.com. It might be related to permission issue. Make sure that your sql services owner should have full access on the folder and file that you are trying to import.

  • @vishnupriya407
    @vishnupriya407 Рік тому

    Can we bulk insert delta table like this from blob storage?

    • @learnssis
      @learnssis  Рік тому

      I have never tried that, you can try it out.

  • @camelCased
    @camelCased Рік тому

    It works for simple cases, but don't even think to mess with CSVs and Microsoft SQL server for data that might contain quotes or newlines - it just will break in one way or another. SQL server is not able nor export nor import ISO standard compatible CSV files.

    • @learnssis
      @learnssis  Рік тому

      For complex cases, try to use SSIS which is built for large data processing.

    • @camelCased
      @camelCased Рік тому

      @@learnssis Unfortunately, if using SSIS to export to CSV files, it will have the same problems with data that has quotes and newlines. There are two great articles about these issues; I cannot link them directly (youtube is aggressive against links lately), but you can find them by names:
      'Comedy Limited' with SQL Server
      Extracting Data from (Azure) SQL Server Huge Tables in RFC 4180-Compliant CSV Files
      Really amusing and sad stories.

    • @learnssis
      @learnssis  Рік тому

      @@camelCased Correct. We can use Fixed width files to export data to flat files if data is huge and contains double quotes or newline characters.

  • @kannann1492
    @kannann1492 Рік тому

    Hey i am getting error. I am using mysql workbench
    10:40:18 BULK INSERT tripdata FROM 'D:\Sample Data\Raw data for Capital Bikeshare\202004.csv' WITH (FORMAT = 'CSV' , FIRSTROW=2 , FIELDTERMINATOR = ',' , ROWTERMINATOR = '0x0a')
    Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'BULK INSERT tripdata FROM 'D:\Sample Data\Raw data for Capital Bikeshare\202004.' at line 1 0.047 sec

    • @learnssis
      @learnssis  Рік тому +1

      You can try this query
      LOAD DATA INFILE 'D:/Files/Sellers.CSV' INTO TABLE sellers
      FIELDS TERMINATED BY ','
      OPTIONALLY ENCLOSED BY '"'
      LINES TERMINATED BY '
      '
      IGNORE 1 ROWS;
      I will make a video on this very soon.

    • @kannann1492
      @kannann1492 Рік тому

      @@learnssis That also not working Because I am working in MYSQL work bench. My CSV File local in my local computer when I try to upload I getting
      Error Code: 1290. The MySQL server is running with the --secure-file-priv option so it cannot execute this statement 0.015 sec

    • @learnssis
      @learnssis  Рік тому

      @@kannann1492 Check this video
      ua-cam.com/video/bG08P9nNLcQ/v-deo.html
      And the query that I shared with you, I tested it in mysql workbench and it is working fine, I will try to make a video on this today.

    • @learnssis
      @learnssis  Рік тому

      @@kannann1492 you can watch the video here how to import a csv file into mysql using a bulk insert query
      ua-cam.com/video/HlnmXv_kCL0/v-deo.html

  • @RaviKumar-tp6ii
    @RaviKumar-tp6ii 2 роки тому

    how to pass a file to import dynamically?

    • @learnssis
      @learnssis  2 роки тому

      Hi Ravi, you won't be able to pass the file dynamically to Bulk insert task. I have shown other options how you can move multiple sql tables from one server to another
      How to transfer multiple sql tables from one server to another
      ua-cam.com/video/YXeEZsGmJrI/v-deo.html
      How to dynamically move multiple sql tables from one server to another
      ua-cam.com/video/-GEShPKmlTw/v-deo.html

  • @foodlovers76
    @foodlovers76 2 роки тому

    How to load multiple Excel files into SQL server by using bulk insert

  • @nareshMerugu
    @nareshMerugu 6 місяців тому

    Sir,we have import the multiple CSV files in one goo is it possible??

    • @learnssis
      @learnssis  6 місяців тому

      I think you can try using cursor and pass one file name at a time to the import sql query and see how it works.

    • @nareshMerugu
      @nareshMerugu 6 місяців тому

      @@learnssis tq for ur reply...but I tried same as but one column doesn't show the data it's showing only data retrieved successfully

    • @nareshMerugu
      @nareshMerugu 6 місяців тому

      How it is possible sir ?

    • @learnssis
      @learnssis  6 місяців тому

      @@nareshMeruguCan you ask chatgpt to write the sql query for you ? It can write the sql query for you, just give him instruction.

    • @learnssis
      @learnssis  6 місяців тому

      @@nareshMerugu
      The below code that I got from google it works for importing multiple csv files, I tested it with 2 files and it worked.
      Provide your folder path at this line
      SET @path = 'D:\Files\'
      And the provide your sql table name at this line
      set @sql = 'BULK INSERT YourTableName FROM ''' + @path +
      stackoverflow.com/questions/16076309/import-multiple-csv-files-to-sql-server-from-a-folder
      EXEC sp_configure 'show advanced options', 1;
      RECONFIGURE;
      EXEC sp_configure 'xp_cmdshell', 1;
      RECONFIGURE;
      go
      --BULK INSERT MULTIPLE FILES From a Folder
      drop table if exists ALLFILENAMES
      --a table to loop thru filenames drop table ALLFILENAMES
      CREATE TABLE ALLFILENAMES(WHICHPATH VARCHAR(255),WHICHFILE varchar(255))
      --some variables
      declare @filename varchar(255),
      @path varchar(255),
      @sql varchar(8000),
      @cmd varchar(1000)
      --get the list of files to process:
      SET @path = 'D:\Files\'
      SET @cmd = 'dir ' + @path + '*.csv /b'
      INSERT INTO ALLFILENAMES(WHICHFILE)
      EXEC Master..xp_cmdShell @cmd
      UPDATE ALLFILENAMES SET WHICHPATH = @path where WHICHPATH is null
      --cursor loop
      declare c1 cursor for SELECT WHICHPATH,WHICHFILE FROM ALLFILENAMES where WHICHFILE like '%.csv%'
      open c1
      fetch next from c1 into @path,@filename
      While @@fetch_status -1
      begin
      --bulk insert won't take a variable name, so make a sql and execute it instead:
      set @sql = 'BULK INSERT YourTableName FROM ''' + @path + @filename + ''' '
      + ' WITH (
      FIELDTERMINATOR = '','',
      ROWTERMINATOR = ''
      '',
      FIRSTROW = 2
      ) '
      print @sql
      exec (@sql)
      fetch next from c1 into @path,@filename
      end
      close c1
      deallocate c1

  • @Deepratan27
    @Deepratan27 Рік тому

    How to do this in PL/SQL

    • @learnssis
      @learnssis  Рік тому

      If you want to do this in MySQL then you take a look at this video
      ua-cam.com/video/HlnmXv_kCL0/v-deo.html

    • @Deepratan27
      @Deepratan27 Рік тому

      @@learnssis Error starting at line : 6 in command -
      FIELDS TERMINATED BY ','
      Error report -
      Unknown Command

    • @Deepratan27
      @Deepratan27 Рік тому

      Not working

    • @learnssis
      @learnssis  Рік тому

      @@Deepratan27 what is your source and destination and on which platform are you executing this query ?