में कनवर्ट करें मेरे पास एक्सेल वर्कशीट (.xls) है। मुझे इसे एसक्यूएल स्क्रिप्ट में बदलने की जरूरत है। एकल एक्सेल वर्कशीट में कई टेबल होते हैं। तो परिणामस्वरूप लिपि में एकाधिक निर्माण तालिका और सम्मिलित बयान होना चाहिए। मैंने http://www.sqlconverter.com/ जैसे विभिन्न टूल की कोशिश की लेकिन मैं उचित समाधान प्राप्त करने में असमर्थ हूं। कोई और तरीका मैं इसे कर सकता हूँ?एक्सेल वर्कशीट को एसक्यूएल स्क्रिप्ट
उत्तर
मैंने आपकी टिप्पणी देखी है कि आयात विज़ार्ड का उपयोग करने से आप समाधान की तुलना में अधिक जटिल थे, इसलिए आपको डेटा लोड करने की कोशिश करनी होगी।
आप BULK INSERT
कोशिश कर सकते हैं:
सबसे पहले, प्रत्येक शीट पर एक के रूप में सहेजें करते हैं और उन्हें CSV फ़ाइलों में रूपांतरित करें। आपके द्वारा आयात की जाने वाली प्रत्येक शीट के लिए आपके पास एक CSV फ़ाइल होनी चाहिए।
अगला, उसी डेटा प्रकार और लंबाई के साथ एक टेबल बनाएं जिसमें आप लाएंगे। एक सामान्य एक्सेल सेल एक वर्चर (255) है, (शायद यदि आप विशिष्ट होना चाहते हैं तो NVARCHAR (255) की तरह अधिक, लेकिन हम इस समाधान के लिए यूनिकोड से बचेंगे)।
इसलिए, यदि आपका एक्सेल शीट 5 कॉलम था:
CREATE TABLE Sheet1
(Column1 VARCHAR(255)
, Column2 VARCHAR(255)
, Column3 VARCHAR(255)
, Column4 VARCHAR(255)
, Column5 VARCHAR(255)
)
फिर आप तालिका बशर्ते आप साझा नेटवर्क या स्थानीय सर्वर/मशीन जहां एसक्यूएल पर फ़ाइल के लिए एक सरल थोक डालने लिख सकते हैं उदाहरण है। उदाहरण के लिए, यदि आपके पास अपनी मशीन पर फ़ाइल थी और नेटवर्क पर सर्वर से बाहर निकलने की कोशिश करना चाहता था, तो एसक्यूएल को लगता है कि नीचे दी गई स्क्रिप्ट में C:\
सर्वर पर था, न कि आपकी मशीन। आप किसी फ़ोल्डर को साझा करने के लिए है और नेटवर्क पर इसे का उपयोग होगा: \\MyMachineName\SharedFolder\Sheet1.csv
BULK INSERT dbo.Sheet1
FROM 'C:\LocalFolder\WhereTheFileIs\Sheet1.csv'
WITH (
FIELDTERMINATOR = ','
, ROWTERMINATOR = '\n'
)
यह है कि तालिका में डेटा स्तंभों की एक ही नंबर प्रदान की गई फ़ाइल और तालिका में मौजूद मिलना चाहिए।
यह सुंदर नहीं है, लेकिन यह आसान है। BULK INSERT
बुनियादी और त्वरित लोडिंग की एक कोशिश की और सही विधि है। सूत्र बस यदि आपके डेटा कॉलम बी, सी और डी sepearate स्तंभ में है बनाने के लिए::
वहाँ भी एक्सेल से समूह डालने के लिए एक सरल तरीका है = '& बी 1 & "," मूल्यों (में डालने "' "& सी 1 &" ',' "& डी 1 &" ')
sqlizer.io एसक्यूएल डालने तालिका परिभाषा के साथ पूरा लिपियों में XLSX, CSV या JSON से टेबल परिवर्तित करने सहित इस करता है, ऑनलाइन उपकरण।
SQLizer.io 5,000 से कम पंक्तियों के रूपांतरण के लिए स्वतंत्र है डेटा –
इसके अलावा http://www.convertcsv.com/csv-to-sql.htm –
यह है vamsi कृष्णा मैसूर द्वारा निर्मित 1.apache apoi यह फ़ाइलें और प्रणाली अपाचे apoi मैं इस परियोजना
package excelread;
import java.io.File;
import java.io.FileOutputStream;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
import org.apache.poi.xwpf.usermodel.UnderlinePatterns;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
public class ExcelRead
{
public static void main(String[] args) throws Exception
{
try
{
FileOutputStream output=new FileOutputStream("result.docx");
FileOutputStream output=new FileOutputStream("result.sql");//sql script in the script
FileOutputStream output=new FileOutputStream("result.xlxs");
FileOutputStream output=new FileOutputStream("result.csv");
XWPFDocument doc=new XWPFDocument();
XWPFParagraph para=doc.createParagraph();
para.setAlignment(ParagraphAlignment.CENTER);
XWPFRun pararun=para.createRun();
pararun.setBold(true);
pararun.setFontSize(20);
pararun.setText("Database Tables\n\n");
File f= new File("C:\\Users\\admin\\Desktop\\BUILDING_TB.xls");//file location where it is stored in the system
Workbook wb= Workbook.getWorkbook(f);
int sheets=wb.getNumberOfSheets();
for(int s1=0;s1<sheets;s1++)
{
System.out.println("for sheet"+s1);
Sheet s= wb.getSheet(s1);
String tbname=s.getName();
XWPFParagraph para1=doc.createParagraph();
para1.setAlignment(ParagraphAlignment.LEFT);
pararun=para1.createRun();
pararun.setText(tbname);
pararun.setFontSize(16);
pararun.setUnderline(UnderlinePatterns.WORDS);
int rows=s.getRows();
int cols=s.getColumns();
int indexrows=0;
int cols1=0;
int indexcols=0;
int pk=1000,dt=1000,cn=1000,ci=1000,dd=1000,n=1000,com=1000;
int ava=0;
List <String> comments= new LinkedList <String>();
List <String> sequence= new LinkedList <String>();
List <String> cid= new LinkedList <String>();
String createQuery="create table " +tbname+"(";
System.out.println(rows+" "+cols);
for(int j=0;j<rows;j++) //TO AVOID EMPTY ROW AND COLUMNS
{
sequence.clear();
for(int i=0;i<cols;i++) //TO GET ONE ROW DETAILS
{
indexcols=0;
cols1=0;
Cell c=s.getCell(i,j);
sequence.add(c.getContents());
}
for(int i=0;i<cols;i++)
{
if(sequence.get(i)=="")
{
cols1= ++indexcols;
}
else
{
ava=1;
indexrows=j;
break;
}
}
if(ava==1)
break;
}
for(;indexcols<cols;indexcols++) //TO ARRANG DATA IN REQUIRED ORDER
{
if(sequence.get(indexcols).toLowerCase().contains("PK".toLowerCase()))
{
pk=indexcols;
}
else if(sequence.get(indexcols).toLowerCase().contains("Column_id".toLowerCase()))
{
ci=indexcols;
}
else if(sequence.get(indexcols).toLowerCase().contains("Column_Name".toLowerCase()))
{
cn=indexcols;
}
else if(sequence.get(indexcols).toLowerCase().contains("nullable".toLowerCase()))
{
n=indexcols;
}
else if(sequence.get(indexcols).toLowerCase().contains("Data_TYpe".toLowerCase()))
{
dt=indexcols;
}
else if(sequence.get(indexcols).toLowerCase().contains("Default".toLowerCase()))
{
dd=indexcols;
}
else if(sequence.get(indexcols).toLowerCase().contains("comments".toLowerCase()))
{
com=indexcols;
}
}
indexrows++;
int rows1=indexrows;
for(;indexrows<rows;indexrows++) //PREPARING QUERY(For excel rows which contain data)
{
indexcols=cols1;
for(;indexcols<cols;indexcols++) //for all columns
{
Cell c=s.getCell(indexcols, indexrows);
String item=c.getContents();
//adding Column name to query
if(indexcols==cn)
{ if(!(item.equals("")) && indexrows!=rows1)
createQuery =createQuery+" ,"+item;
else if(item.equals(""))
break;
else
createQuery =createQuery+" "+item;
}
//adding data type to query
if(indexcols==dt)
{
createQuery =createQuery+" "+item;
}
//adding data default to query
else if(indexcols==dd)
{
if(item=="")
continue;
else
createQuery =createQuery+" "+"default "+item;
}
//addig primary key constaint to query
else if(indexcols==pk)
{
if(item.equalsIgnoreCase("true"))
createQuery =createQuery+" "+"primary key";
else
createQuery =createQuery+" "+"";
}
//adding not null constraint to query
else if(indexcols==n)
{
if(item.equalsIgnoreCase("no"))
createQuery =createQuery+" "+"not null";
else
createQuery =createQuery+" "+"";
}
//adding comments
else if(indexcols==com)
{
if(item!="")
{
comments.add(item);
}
else
{
comments.add("comments empty");
}
}
else if(indexcols==ci)
{
if(item!=null)
{
cid.add(item);
}
}
}//column loop close
}//row looop close
createQuery=createQuery+")";
System.out.println(createQuery);
XWPFParagraph para2=doc.createParagraph();
para2.setAlignment(ParagraphAlignment.LEFT);
pararun=para2.createRun();
pararun.setFontSize(14);
pararun.setText(createQuery+";");
System.out.println("table created successfully");
}//sheets loop closse
doc.write(output); //writing data into ouptu file
output.close();
}//try block close
catch(Exception e)
{
System.out.println(e.toString());
}
}//main close
}//class close
AFAIK एमएस एसक्यूएल सर्वर एक डेटाबेस में एक्सेल शीट लोड करने के लिए कुछ कार्य प्रदान में sused में जोड़ा जाना चाहिए इस्तेमाल किया जाना चाहिए: http: // support.microsoft.com/kb/321686 – muehlbau
मैंने पहले यह लिंक देखा लेकिन यह काफी जटिल है और मैं इसे पाने में असमर्थ हूं .. मुझे इसके लिए एक आसान समाधान चाहिए – user1402867