sql-server-2005

Comma Separated List of all columns in the Database (Tablename | Column_names…)

爱⌒轻易说出口 提交于 2019-12-20 12:40:46
问题 In SQL Server, I would like see Table_Name and all the Columns associated with that Table_Name in a database. So the Output should look like this: TABLE_NAME COLUMN_NAME 1. Employee Employee-id, Lastname, Firstname, Title........... 2. Orders Orderid, Order-date, shipped-date, delivery-date....... 3. Products Product-id, Product-name, supplier-id, category-id..... 4. Suppliers Supplier-id, Company-name, contact-name....... 5. ............................................................ 6. ...

How to check when autogrowth is done last?

女生的网名这么多〃 提交于 2019-12-20 12:34:10
问题 In sql server 2005, the autogrowth is enabled by size. Is there any way to check when autogrowth on data and log file happened last? 回答1: SSMS, right click your db, go to reports->standard reports->disk usage and look for Autogrow/Autoshrink events . Hopefully you have the correct trace levels set up, if not you might have some issues finding out history. 回答2: Here's how to do it without using the sql reports(link, followed by relevant TSQL): https://sqlblog.org/2007/01/11/reviewing-autogrow

How to run a sql script using C# [duplicate]

假如想象 提交于 2019-12-20 12:32:57
问题 This question already has answers here : How to execute an .SQL script file using c# (10 answers) Closed 4 years ago . I have a sql script to create a new database which i need to create when our product is installed. For this i need to fire the script using c#. DB is sql-server 2005 express. Plz help.... The sql script is as follows: USE [master] GO /****** Object: Database [Jai] Script Date: 02/12/2010 11:01:25 ******/ CREATE DATABASE [Jai] ON PRIMARY ( NAME = N'Jai', FILENAME = N'C:

How to generate a csv file using select query in SQL [duplicate]

◇◆丶佛笑我妖孽 提交于 2019-12-20 12:29:33
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: How to export data as CSV format from SQL Server using sqlcmd? I want to generate CSV file using select query in SQL-server. The code below is working correctly in mySQL: select * into outfile 'd:/report.csv' fields terminated by ',' from tableName; It generated the CSV file. Does anybody know how can I create a CSV file using select query in SQL-server? 回答1: Will this do the work sqlcmd -S server -U loginid -P

“select * into table” Will it work for inserting data into existing table

风流意气都作罢 提交于 2019-12-20 12:27:55
问题 I am trying to insert data from one of my existing table into another existing table. Is it possible to insert data into any existing table using select * into query. I think it can be done using union but in that case i need to record all data of my existing table into temporary table, then drop that table and finally than apply union to insert all records into same table eg. select * into #tblExisting from tblExisting drop table tblExisting select * into tblExisting from #tblExisting union

SQL Server 2005/2008: Insert a File in an varbinary(max) column in Transact-SQL

[亡魂溺海] 提交于 2019-12-20 11:51:31
问题 Is it possible to insert a file in a varbinary(max) column in Transact-SQL? If yes, I would be very please to have a code snippet to at least give me an idea how to do that. Thanks 回答1: It's so easy - once you know it! :-) Found this on Greg Duncan's blog a while ago: INSERT INTO YourTable(YourVarbinaryColumn) SELECT * FROM OPENROWSET(BULK N'(name of your file to import)', SINGLE_BLOB) AS import And here's the MSDN library documentation on it. Marc 来源: https://stackoverflow.com/questions

How to undo a SQL Server UPDATE query?

浪子不回头ぞ 提交于 2019-12-20 11:14:28
问题 In SQL Server Management Studio, I did the query below. Unfortunately, I forgot to uncomment the WHERE clause. 1647 rows were updated instead of 4. How can I undo the last statement? Unfortunately, I've only just finished translating those 1647 rows and was doing final corrections , and thus don't have a backup . UPDATE [dbo].[T_Language] SET [LANG_DE] = 'Mietvertrag' --<LANG_DE, varchar(255),> ,[LANG_FR] = 'Contrat de bail' -- <LANG_FR, varchar(255),> ,[LANG_IT] = 'Contratto di locazione' --

How to preserve an ampersand (&) while using FOR XML PATH on SQL 2005

假装没事ソ 提交于 2019-12-20 11:09:11
问题 Are there any tricks for preventing SQL Server from entitizing chars like &, <, and >? I'm trying to output a URL in my XML file but SQL wants to replace any '&' with ' & ' Take the following query: SELECT 'http://foosite.com/' + RTRIM(li.imageStore) + '/ImageStore.dll?id=' + RTRIM(li.imageID) + '&raw=1&rev=' + RTRIM(li.imageVersion) AS imageUrl FROM ListingImages li FOR XML PATH ('image'), ROOT ('images'), TYPE The output I get is like this (&s are entitized): <images> <image> <imageUrl>http

Query the contents of stored procedures on SQL Server

☆樱花仙子☆ 提交于 2019-12-20 11:05:57
问题 I am exploring a legacy database system and have very little knowledge of its internals. I would like to find all the stored procedures that invoke another stored procedure A . How best to do this? Can I write something like this pseudocode: select name from AllStoredProcedures as Asp where Asp.TextualContent contains 'A' Asp.TextualContent means the actual SQL contained in the SP. 回答1: SELECT OBJECT_NAME(OBJECT_ID), definition FROM sys.sql_modules WHERE objectproperty(OBJECT_ID, 'IsProcedure

Why a simple T-SQL UDF function makes the code execution 3 times slower

霸气de小男生 提交于 2019-12-20 10:47:25
问题 I'm rewriting some old stored procedure and I've come across an unexpected performance issue when using a function instead of inline code. The function is very simple as follow: ALTER FUNCTION [dbo].[GetDateDifferenceInDays] ( @first_date SMALLDATETIME, @second_date SMALLDATETIME ) RETURNS INT AS BEGIN RETURN ABS(DATEDIFF(DAY, @first_date, @second_date)) END So I've got two identical queries, but one uses the function and the other does the calculation in the query itself: ABS(DATEDIFF(DAY,