Home Database Mysql Tutorial SqlServer数据库表导入SqlLite数据库表保持日期时间类型字段的格

SqlServer数据库表导入SqlLite数据库表保持日期时间类型字段的格

Jun 07, 2016 pm 03:35 PM
sqlserver import database date

在写查询功能的过程中遇到一个这样的问题:按日期范围查询,sql语句是:where dt=用户选择起始日期dt=用户选择结束日期。数据库中的数据如图1,我选择的测试数据起始时间是2008-01-06结束日期是2009-06-01。期望的结果应该能查出第一条数据。执行sql语句并无

在写查询功能的过程中遇到一个这样的问题:按日期范围查询,sql语句是:where dt>=用户选择起始日期&&dt

SqlServer数据库表导入SqlLite数据库表保持日期时间类型字段的格

           图1

这时的解决办法是把数据库中数据的格式更改为YYYY-MM-dd。问题来了。

用户用的数据库是Sqlserver,因开发需要我们公司用的是Sqlite数据库,需要将用户的Sqlserver数据表导入到我们的Sqlite数据库。SqlServer数据库中时间格式是YYYY-MM-dd HH:mm:ss(SqlServer数据库会把插入的datetime类型数据自动规范成YYYY-MM-dd HH:mm:ss类型)导入时我选择的是Navicat Premium工具。导入数据成功,在Sqlite中打开数据表时发现表中数据是YYYY-M-d格式。原因是Sqlite数据库不支持datetime类型的数据,因此数据库中dt是Text类型,不能像Sqlite那样自动规范日期字段格式。如图1:Sqlite中数据是2009-6-1没有补0,测试数据选择的结束日期2009-06-01,比较时6>0,所以数据库第一条数据没有查询出来。

解决办法是:先把SqlServer中的数据导入到Excel中,再把.xls导入到Sqlite数据库。

1.把SqlServer中的数据导入到Excel中。导入之前先新建一个Excel文档,把数据库中的字段名写到第一行作为列头(即把此文档作为数据导入的模板)如图2。导出时使用SqlServer自带的导出数据功能,具体方法不再详细叙述。在选择目标时,Excel文件路径选择建好的Excel文档,首行包含列名称项可选可不选如图3。

SqlServer数据库表导入SqlLite数据库表保持日期时间类型字段的格                               SqlServer数据库表导入SqlLite数据库表保持日期时间类型字段的格

                    图2                                                                                                        图3

注意:如果不在导出之前写上列头建好Excel模板,导出时会报错如图4。如果导出的日期时间仍不会补0,尝试新建Excel模板,选中日期列右键设置单元格格式为文本,然后重复以上步骤。

SqlServer数据库表导入SqlLite数据库表保持日期时间类型字段的格

                                                                   

 

 

 

 

 

 

 

 

                                       图4 

2.最后将导出成功的Excel文档导入到Sqlite数据库,使用Navicat Premium工具即可做到,使用该工具导入时可选择日期时间类型数据的分隔符是-还是/。具体导入方法不再叙述。

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

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 import mdf file into sqlserver How to import mdf file into sqlserver Apr 08, 2024 am 11:41 AM

The import steps are as follows: Copy the MDF file to SQL Server's data directory (usually C:\Program Files\Microsoft SQL Server\MSSQL\DATA). In SQL Server Management Studio (SSMS), open the database and select Attach. Click the Add button and select the MDF file. Confirm the database name and click the OK button.

How to delete sqlserver if the installation fails? How to delete sqlserver if the installation fails? Apr 05, 2024 pm 11:27 PM

If the SQL Server installation fails, you can clean it up by following these steps: Uninstall SQL Server Delete registry keys Delete files and folders Restart the computer

What is the difference between mysql and sqlserver syntax What is the difference between mysql and sqlserver syntax Apr 22, 2024 pm 06:33 PM

The syntax differences between MySQL and SQL Server are mainly reflected in database objects, data types, SQL statements and other aspects. Database object differences include the storage engine and how filegroups are specified, and the creation of indexes and constraints. Data type differences involve differences in numeric types, character types, and date and time types. SQL statement differences are reflected in result set limitations, data insertion, update and delete operations, etc. Other differences include how identity columns, views, and stored procedures are created. Understanding these differences is important to avoid errors when using different database systems.

What should I do if sqlserver cannot be deleted and cannot be reinstalled? What should I do if sqlserver cannot be deleted and cannot be reinstalled? Apr 05, 2024 pm 11:30 PM

The problem that SQL Server cannot be reinstalled due to incomplete deletion can be solved by following the following steps: manually delete files and registry entries; use SQL Server installation and uninstall tools; use third-party uninstall tools; check Windows Event Viewer; restart the computer; reinstall SQL Server.

How does Hibernate implement polymorphic mapping? How does Hibernate implement polymorphic mapping? Apr 17, 2024 pm 12:09 PM

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

Where is the navicat database file? Where is the navicat database file? Apr 23, 2024 am 10:57 AM

The location where the Navicat database configuration files are stored varies by operating system: Windows: The user-specific path is %APPDATA%\PremiumSoft\Navicat\macOS: The user-specific path is ~/Library/Application Support/Navicat\Linux: The user-specific path is ~/ .config/navicat\The configuration file name contains the connection type, such as navicat_mysql.ini. These configuration files store database connection information, query history, and SSH settings.

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

An in-depth analysis of how HTML reads the database An in-depth analysis of how HTML reads the database Apr 09, 2024 pm 12:36 PM

HTML cannot read the database directly, but it can be achieved through JavaScript and AJAX. The steps include establishing a database connection, sending a query, processing the response, and updating the page. This article provides a practical example of using JavaScript, AJAX and PHP to read data from a MySQL database, showing how to dynamically display query results in an HTML page. This example uses XMLHttpRequest to establish a database connection, send a query and process the response, thereby filling data into page elements and realizing the function of HTML reading the database.

See all articles