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

Undress AI Tool

Undress AI Tool

Undress images for free

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.

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)

Hot Topics

PHP Tutorial
1510
276
Windows 11 Xtreme LiteOS ISO for Low-End PC, Quick Install Windows 11 Xtreme LiteOS ISO for Low-End PC, Quick Install Jul 16, 2025 am 12:01 AM

If your computer is not compatible with Windows 11, you can try Xtreme LiteOS 11 which is a lite system based on Windows 11. So, how to download Windows 11 Xtreme LiteOS and install this lite operating system for low-end PCs? Follow the instructions

How to Set Up a Dual Monitor Display on Windows How to Set Up a Dual Monitor Display on Windows Jul 27, 2025 am 04:16 AM

TosetupdualmonitorsonWindows,firstcheckhardwarecompatibilitybyensuringyourGPUhasmultiplevideoportsandyouhavethecorrectcables;connectthesecondmonitor,poweronbothdisplays,andletWindowsdetectthemautomatically;thenopenDisplaysettings,identifyandarrangeth

[10 Ways] How to Open Windows 11 PowerShell Quickly/Easily? [10 Ways] How to Open Windows 11 PowerShell Quickly/Easily? Jul 16, 2025 am 12:13 AM

This article commented by php.cn official website mainly teaches you ten solutions to launch Windows 11 PowerShell, including but not limited to through Start menu, Search, Run, CMD, Command Prompt…

how to sync my phone to my computer how to sync my phone to my computer Jul 19, 2025 am 04:37 AM

Tosyncyourphonewithyourcomputer,useaUSBcablefordirectfiletransfer,enableautomaticphotosyncingviaGooglePhotosoriCloud,andutilizecloudserviceslikeGoogleDrive,Dropbox,iCloud,orOneDriveforgeneralfilesyncing.First,connectyourphoneviaUSBandselectthecorrect

Logitech Options & Logi Options  |Download/Install/Uninstall - MiniTool Logitech Options & Logi Options |Download/Install/Uninstall - MiniTool Jul 19, 2025 am 12:48 AM

What is Logitech Options software? What is Logi Options ? What is the difference between Logitech Options and Options ? How to get them? Read this post from php.cn and you can find much information on these two programs and Logitech Options download

How Can I Install Chrome Extensions on Android Devices? How Can I Install Chrome Extensions on Android Devices? Jul 16, 2025 am 12:03 AM

Perhaps you want to install Chrome extensions on Android, but you don’ know how to do it. If you are bothered by this issue, this php.cn post is helpful to you. In this post, we will show you how to install Chrome Android extensions on different web

how to use the ping command how to use the ping command Jul 16, 2025 am 02:18 AM

The ping command is used to test network connectivity, and determines the communication status by sending ICMP echo request packets and waiting for a response. When using it, open the command line tool and enter the ping target address (such as pinggoogle.com or ping8.8.8.8), and the system will display information such as round trip time and packet loss rate; Windows sends 4 packets by default, and Linux/macOS continues to send until interrupted. To determine the problem, you can execute it in sequence: 1.ping127.0.0.1 check the local protocol stack; 2.ping the default gateway checks the LAN connection; 3.ping the external address checks the external network or DNS. High latency or packet loss can try restarting the router, checking the network cable, or contacting the ISP. Advanced parameters include Linux/m

How to Fix the Error Code: Edge Out of Memory? Six Methods How to Fix the Error Code: Edge Out of Memory? Six Methods Jul 16, 2025 am 12:08 AM

Microsoft Edge, as an excellent browser, has a bunch of loyal customers but, some of them encounter troubles when running Edge – “out of memory” crashes. It is such a pity to hear that you ran into this frustrating issue, but now don’t worry, this po

See all articles