sql-server-2005

How do I delete all tables in a database using SqlCommand?

孤人 提交于 2019-12-24 08:57:10
问题 Unlike the other posts about the task "delete all tables", this question is specifically about using SqlCommand to access the database. A coworker is facing the problem that no matter how it attempts it, he can't delete all tables from a database via SqlCommand. He states that he can't perform such action as long as there is an active connection - the connection by the SqlCommand itself. I believe this should be possible and easy, but I don't have much of a clue about databases so I came here

Use SQL instead of Delete and End from keyboard

你说的曾经没有我的故事 提交于 2019-12-24 08:47:54
问题 I am running a simple statment below which gives the output as follow: select '''' + name + '''' + ',' as Emp_Names from dbo.employee Emp_Names 'Jason', 'Robert', 'Celia', 'Linda', 'David', 'James', 'Alison', 'Chris', 'Mary', Is there a way in SQL that can show my desired output as: Emp_Names 'Jason', 'Robert','Celia','Linda','David','James','Alison','Chris','Mary', i can press a Delete and End together to get there but only for a handful records but not for a hundred records... Thanks all! i

UPDATE with a stored procedure on SQL Server 2005

北慕城南 提交于 2019-12-24 08:34:29
问题 UPDATE users SET field = my_sp() in SQL Server 2005. Apparently I can't do this and have to use some form of EXEC. Can anyone help me out and let me know how to do this? This should be some easy rep. 回答1: To assign value you need to use sql function. it is impossible to assign value from stored procedure. Here is link how to create it. 回答2: you need to write a scalar function that takes some parameters (or even zero) and returns what you need. 回答3: You could store the output of the stored

command line to create data source with sql authentication?

时间秒杀一切 提交于 2019-12-24 08:11:38
问题 I'm looking to run a batch file on windows xp professional which creates a system odbc data source for a sql server connection. I can do that with: ODBCCONF.exe CONFIGSYSDSN "SQL Server" "DSN=Kappa| Description=Kappa Data Source | SERVER=10.100.1.10 | Trusted_Connection=Yes | Database=subscribers" However I need a way to set the sql server authentication to be "With SQL Server authentication using a login ID and password entered by the user." to be set and preset the login id and pass. Any

Group columns into multiple rows and Group_concate like MySQL in SQL Server

冷暖自知 提交于 2019-12-24 07:35:56
问题 I’ve been looking for a way to show one column in multiple rows, one cell. The content of it separated by comma’s. For example, in stead of: ProjectID Name count ------------------------------------- 2 Technical Services 31 1 Security Services 32 7 Technical Services 32 I would like the result of my query to look like this: Name Label --------------------------- Technical Services 31,2 Technical Services 32,7 Security Services 32,1 I also want the result of my query to look like this: (like

Sql query number of occurrence

可紊 提交于 2019-12-24 07:35:29
问题 I wanna to have query: Select cars.* from cars where cars.code in ( select carCode from articles where numberofrecords with this car (it is not a column) >1 and Accepted=1 order by date ) How to write it? 回答1: This should do it: SELECT c.* FROM cars c JOIN ( SELECT carCode FROM articles WHERE Accepted = 1 GROUP BY carCode HAVING COUNT(carCode) > 1 ) a ON c.code = a.carCode 回答2: Try something like this: SELECT cars.* FROM cars WHERE cars.code IN ( SELECT carCode FROM articles WHERE Accepted =

How do I compare two datetime fields in SQL Server 2005?

三世轮回 提交于 2019-12-24 07:26:15
问题 DECLARE @p_date DATETIME SET @p_date = CONVERT( DATETIME, '14 AUG 2008 10:45:30',?) SELECT * FROM table1 WHERE column_datetime = @p_date I need to compare date time like: @p_date=14 AUG 2008 10:45:30 column_datetime=14 AUG 2008 10:45:30 How can I do this? 回答1: The question is unclear, but it looks like you are trying to do the equality match that isn't returning the rows you expect, so I'm guessing that the problem is that the milliseconds are being problematic. There are several approaches

System Views text in SQL Server 2005

ⅰ亾dé卋堺 提交于 2019-12-24 07:13:42
问题 I am looking for viewing the text of the system views and procedures in SQL Server 2005 using the object explorer or using sp_helptext. actually i am coming from the SQL Server 2000 background, where we have the feature of retreiving the code of the view and the stored procedure using SQL Server 2000 Enterprise manager directly, but still i am unable to find this feature in the SQL Server 2005 Management Studio and still looking for the same feature for getting the view and procedure text in

Create failed for database , SMO,C#

﹥>﹥吖頭↗ 提交于 2019-12-24 07:09:54
问题 I am trying to create a new database programmatically using SMO (c#). I am working on SQL Server 2005. This is the code : ServerConnection connection = new ServerConnection(serverName, userName, password); Server sqlServer = new Server(connection); Database newDB = new Database(sqlServer, databaseName); newDB.Create(); I get the exception : "Create failed for database." What could be the problem and how can I create a new DB? thanks... 回答1: I tried this: with a sysadmin user, everything works

tsql - Batch insert performance

非 Y 不嫁゛ 提交于 2019-12-24 07:03:08
问题 I would like to improve the speed of some inserts on an application I am working on. I had originally created a batch like this: insert tableA (field1, field2) values (1,'test1'), (2, 'test2') This works great on SQL Server 2008 and above, but I need my inserts to work on SQL Server 2005. My question is would I get any performance benefit using a batch like this: insert tableA (field1, field2) select 1, 'test1' union all select 2, 'test2' Over this batch: insert tableA (field1, field2) values