ssms

高版本数据库导出到低版本,sql2012到sql2005

怎甘沉沦 提交于 2019-12-25 13:03:45
SQLServer提供了多种数据导出导入的工具和方法,在此,分享我实践的经验(只涉及数据库与Excel、数据库与文本文件、数据库与数据库之间的导出导入)。 (一)数据库与Excel 方法1: 使用数据库客户端(SSMS)的界面工具。右键选择要导出数据的数据库,选择“任务”——“导出数据”,下图1,按照向导一步一步操作即可。而导入则相反,导入时,SQLServer会默认创建一张新表,字段名也默认跟导入的Excel标题一样,并且会默认字段数据类型等。当然在可以在向导进行修改。需要注意的是如果标题不是英文而是中文,默认创建字段名也是中文,这将给后面数据更新操作带来麻烦,所以最好还是以有意义的英文字段名。把数据导入后,再通过执行语句,把数据插入/更新到业务表。 figure-1:任务——导出数据 方法2: 从SQLServer2005开始,可以直接在SSMS上查询出来的结果复制,然后粘贴到Excel上,对于少量数据来说,是非常快速方便的,需要注意的是长数字可能会变成科学记数法的形式,提前在Excel上指定列的格式为文本即可。 导入的话,ctrl + c 复制Excel上的数据,然后在选择相关表,编辑数据,把数据直接粘贴上去即可。但是不建议直接粘贴到业务表(如果表是空白没有数据,并且字段顺序对应,可以这样操作),而是建议先粘贴到一个新建的中间表中,然后再通过语句,把数据插入/更新到业务表。

extract of text from column and copy it into a new column

非 Y 不嫁゛ 提交于 2019-12-25 11:11:50
问题 I want to extract text from a column and place it into a column of its own. The Text is always 16 characters long in a DD/MM/YYYY HH:MM format, appears the text "On-site" which only ever appears once in the text and is always followed by the text "Off-Site" which also only appears once. This is the code that I am using at the moment but I dont have it set right at all. WITH LEFT(SUBSTRING(eventcomments, CHARINDEX('On-Site', r.eventcomments) + 1, 16), CHARINDEX('Off-Site', r.eventcomments) - 1

extract of text from column and copy it into a new column

别来无恙 提交于 2019-12-25 11:10:19
问题 I want to extract text from a column and place it into a column of its own. The Text is always 16 characters long in a DD/MM/YYYY HH:MM format, appears the text "On-site" which only ever appears once in the text and is always followed by the text "Off-Site" which also only appears once. This is the code that I am using at the moment but I dont have it set right at all. WITH LEFT(SUBSTRING(eventcomments, CHARINDEX('On-Site', r.eventcomments) + 1, 16), CHARINDEX('Off-Site', r.eventcomments) - 1

creating a SQL table with multiple columns automatically

↘锁芯ラ 提交于 2019-12-25 05:48:09
问题 I must create an SQL table with 90+ fields, the majority of them are bit fields like N01, N02, N03 ... N89, N90 is there a fast way of creating multiple fileds or is it possible to have one single field to contain an array of values true/false? I need a solution that can also easily be queried. 回答1: At least you can generate ALTER TABLE scripts for bit fields, and then run those scripts. DECLARE @COUNTER INT = 1 WHILE @COUNTER < 10 BEGIN PRINT 'ALTER TABLE table_name ADD N' + RIGHT('00' +

Problems with Data Script Generation

放肆的年华 提交于 2019-12-25 05:13:41
问题 I very rarely use SQL Server and in a professional context I keep well clear! I'm working on a pet project though and I'm have problems with a script creation. I've got an online database that I need to extract everything out of. I use the Tasks > Generate Scripts option within SQL Server Management Studio. The following is an example of one insert statement the script creates (I have 1,000s of these inserts): INSERT [dbo].[NewComics] ([NewComicId], [Title], [Subtitle], [ReleaseDate],

Creating Registered Servers via Powershell in SSMS

本秂侑毒 提交于 2019-12-25 03:14:58
问题 A cool trick that used to work for me is creating Registered Server groups and registrations in SQL Server Management Studio via PowerShell. However, now that I am running the current version (SSMS 17.9.1) I find the functionality has been lost. I'm not sure when it broke. After installing the SQLServer module: Install-Module -Name SqlServer you can open a PowerShell prompt by right-clicking on server group in the Registered Servers window, and clicking Start Powershell. Here, in the past, I

Firewall rules to allow remote connection to SQL Server in a different domain

喜欢而已 提交于 2019-12-24 17:25:45
问题 I recently installed SQL Server Express 2014 on a series of machines running Windows Server 2012. Seven machines in total. All but 1 of them live in the same local domain company.local . A single rogue machine lives in a different public domain public.company.org . The installation process on this machine on a separate domain was carried out by someone who was not paying much attention to the process and pretty much selected all defaults (a.k.a. a click-click-click installation.) As such,

SQL LocalDB - Cannot delete a DB when its files are deleted

家住魔仙堡 提交于 2019-12-24 12:55:11
问题 How can I delete a SQL LocalDB database that has had its files delete? Dropping the database yields this message: Unable to open the physical file "C:\Users\Public\Documents\LocalDB.Tests.3d0d7339-7cf2-45fe-a83b-b5079112ab80.mdf". Operating system error 2: "2(The system cannot find the file specified.)". File activation failure. The physical file name "C:\Users\Public\Documents\LocalDB.Tests.3d0d7339-7cf2-45fe-a83b-b5079112ab80_log.ldf" may be incorrect. Running master.sp_databases actually

Connecting to SQL Server Database using a Hosted Web Application

六月ゝ 毕业季﹏ 提交于 2019-12-24 08:23:56
问题 I have created a .net web application using c# that inserts, updates, and deletes data from an SQL server database. I have tested it using my localhost and it works fine. Now I would like to publish this application on a hosted site. My question is, does the database need to be on the same server/host that the application is in for it to connect? Does anyone have any tips on how to implement this? 回答1: If your Question is 'How to connect database present on another server', then you have to

In SSMS, when editing a stored proc, how to get the line and error numbers to match?

大憨熊 提交于 2019-12-24 07:35:21
问题 Terribly worded question above (trying to be short). Lets try that again: In Microsoft SQL Server Management Studio, when you are editing an SP and execute the sp in the same window, errors show up at the bottom of the screen you can double click to highlight the code causing the error. However, this never lines up, usually being anywhere between 6 to 13 lines from the actual error, usually lower. It will highlight things like comments, etc. Anyone know how to get these to line up? What