Home Computer Tutorials Computer Knowledge What are the steps and methods for inserting data into SQL SERVER database?

What are the steps and methods for inserting data into SQL SERVER database?

Jan 17, 2024 pm 01:45 PM

如何向SQL SERVER数据库插入数据

How to insert data into SQL SERVER database

1. Open sql2008 and log in using windows identity

2. After logging in, right-click and select "Properties". Select "Security" on the left and check "SQL Server and Windows Authentication Mode" on the right to enable mixed login mode

3. Select "Connect", check "Allow remote connections to this server", and then click "OK"

4. Expand "Security", "Login Name"; "sa", right-click and select "Properties"

5. Select "General" on the left, select "SQL Server Authentication" on the right, and set the password

6. Right-click the database and select "Aspect"

7. Select "Server Configuration" in the drop-down box on the right; set the "RemoteAccessEnabled" property to "True" and click "OK"

8. SSMS has been set up now. Log out first, and then log in with sa. Success means that the sa account has been enabled

9. Open the sql server configuration manager

10. Next, start configuring SSCM, select "SQL Server Service" on the left, and ensure that "SQL Server" and "SQL Server Browser" on the right are running

How to import data from Excel table into SQLSERVER database

In the query analyzer, select Lee to operate the database object and write the SQL statement directly:

If you are importing data into an existing table, use

INSERT INTO table SELECT * FROM OPENROWSET('MICROSOFT.JET.OLEDB.4.0'

,'Excel 5.0;HDR=YES;DATABASE=c:test.xls',sheet1$)

form

If you are importing data and adding a new table, use

SELECT * INTO table FROM OPENROWSET('MICROSOFT.JET.OLEDB.4.0'

,'Excel 5.0;HDR=YES;DATABASE=c:test.xls',sheet1$)

form.

The above statement is to read in all the columns in the SHEET1 worksheet in the EXCEL file. If you only want to import some columns, you can

INSERT INTO table (a1,a2,a3) SELECT a1,a2,a3 FROM OPENROWSET('MICROSOFT.JET.OLEDB.4.0'

,'Excel 5.0;HDR=YES;DATABASE=c:test.xls',sheet1$)

In fact, you can use OPENROWSET('MICROSOFT.JET.OLEDB.4.0'

,'Excel 5.0;HDR=YES;DATABASE=c:test.xls',sheet1$) as a table, for example, I wrote such a sentence:

INSERT INTO eval_channel_employee(channel,employee_id)

SELECT CASE a.Channel WHEN 'DIY' THEN 1 WHEN 'RDC' THEN 0 WHEN 'KCM' THEN 2 ELSE 3 END

,b.id FROM

OPENROWSET('MICROSOFT.JET.OLEDB.4.0'

,'Excel 5.0;HDR=YES;DATABASE=c:tempname.xls',sheet1$) AS a,pers_employee b

WHERE a.Employee code =b.code

simple way:

The import function can be directly implemented in SQL2005. I don’t know if it is possible in SQL2008.

The operation process is as follows:

Step one: Log in to SQL Server Management Studio,

Step 2: Right-click "Manage" in "Object Explorer" and click "Import Data" in the pop-up list

Step 3: Click "Next" in the "Import Wizard" dialog box, enter the "Select Data Source" dialog box, select "Microsoft Excel" in the "Data Source" list, and select the corresponding Excel. document, click "Next" when completed (be sure to check "First row contains column names" in this dialog box, so it is to change the column titles in the Excel document to the column item titles in the database table)

Step 4: Specify the target database service, click "Next"... until "Complete"

Step 5: Re-enter SQL Server Management Studio, enter the imported database table, and you can find the imported Excel document data.

You can try the following:

Open SQL Server Configuration Manager and enable SQL Server Agent (instance name). Change startup mode to "Auto"

How to efficiently batch import data into SqlServer

2.SqlBulkCopy is a good choice, it can be imported directly into the database from DataTable

, but please note that (1) the column name is consistent with the target table (2) the data type is consistent (3) null value fault tolerance processing, reference code: ///

data is inserted into the database in batches. ///

///

To batch insert

///

The amount of data written in each batch.

(DataTable dataTable,(DataTable dataTable,

stringtableName,

intbatchSize =10000){using(SqlConnection connection =newSqlConnection(myConnectionString)){try{connection.Open(); //Add leading and leading characters to the table name using(varbulk =newSqlBulkCopy(connection, SqlBulkCopyOptions.KeepIdentity,

null){DestinationTableName=tableName,

BatchSize=batchSize}) {//Loop through all columns and add mapping to bulk//dataTable.EachColumn(c = bulk.ColumnMappings.Add(c.ColumnName, c.ColumnName), c = !c.AutoIncrement); foreach(DataColumn dcindataTable.Columns){bulk.ColumnMappings.Add(dc.ColumnName, dc.ColumnName);}bulk.WriteToServer(dataTable);

bulk.Close();}returntrue;}catch(Exception exp){returnfalse;}finally{connection.Close();}}}

3. If the amount of data is very large, exceeding 10W, you can consider generating a .dtsx file and then calling it directly from the C# code. The efficiency is still good.

The above is the detailed content of What are the steps and methods for inserting data into SQL SERVER database?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to Fix the Steam Cloud Error? Try These Methods How to Fix the Steam Cloud Error? Try These Methods Apr 04, 2025 am 01:51 AM

The Steam Cloud error can be caused by many reasons. To play a game smoothly, you need to take some measures to remove this error before you launch the game. php.cn Software introduces some best ways as well as more useful information in this post.

Windows Metadata and Internet Services Problem: How to Fix It? Windows Metadata and Internet Services Problem: How to Fix It? Apr 02, 2025 pm 03:57 PM

You may see the “A connection to the Windows Metadata and Internet Services (WMIS) could not be established.” error on Event Viewer. This post from php.cn introduces how to remove the Windows Metadata and Internet Services problem.

How to Resolve the KB5035942 Update Issues – Crashing System How to Resolve the KB5035942 Update Issues – Crashing System Apr 02, 2025 pm 04:16 PM

KB5035942 update issues - crashing system commonly happens to users. Inflicted people hope to find a way out of the kind of trouble, such as crashing system, installation, or sound issues. Targeting these situations, this post published by php.cn wil

Fixed – OneDrive Not Uploading Photos on PC Fixed – OneDrive Not Uploading Photos on PC Apr 02, 2025 pm 04:04 PM

OneDrive is an online cloud storage service from Microsoft. At times, you might find OneDrive fail to upload photos to the cloud. If you are on the same boat, keep reading this post from php.cn Software to get effective solutions now!

Fix: Brothers: A Tale of Two Sons Remake Not Launching/Loading Fix: Brothers: A Tale of Two Sons Remake Not Launching/Loading Apr 02, 2025 am 02:40 AM

Is Brothers: A Tale of Two Sons Remake not launching? Encountering Brothers: A Tale of Two Sons Remake black screen? Here this post on php.cn offers you tested solutions to assist you in addressing this problem.

Remove PC App Store Malware - A Full Guide for You! Remove PC App Store Malware - A Full Guide for You! Apr 04, 2025 am 01:41 AM

If you have a program called PC App Store on your computer and did not purposely install it, then your PC may be infected with the malware. This post from php.cn introduces how to remove PC App Store malware.

How to Use Chris Titus Tool to Create a Debloated Win11/10 ISO How to Use Chris Titus Tool to Create a Debloated Win11/10 ISO Apr 01, 2025 am 03:15 AM

Chris Titus Tech has a tool called Windows Utility that can help you easily create a debloated Windows 11/10 ISO to install a clean system. php.cn offers a full guide on how to do this thing using the Chris Titus tool.

Effortles Fixes for Black Screen After Installing a Graphics Driver Effortles Fixes for Black Screen After Installing a Graphics Driver Apr 15, 2025 am 12:11 AM

Have you ever encountered a black screen after installing a graphics driver like an Nvidia driver in Windows 10/11? Now in this post from php.cn, you can find a couple of worth trying solutions to the Nvidia driver update black screen.

See all articles