sql-server

SQL CLR DDL trigger written on C#

Is it possible to create a database/DDL trigger in C#? And, if so, then how? [EDIT] Basically, I decided to use CLR for the database trigger because I want to utilize C# SMO to script the objects that change and insert the object script into a table that tracks versions of database objects. ...

Is it possible to update a variable field in a stored procedure?

I have a simple query that updates a variable column. This query is later string.Formatted and passed to SqlCommand (c#) (TableId is a column in SomeTable): "UPDATE SomeTable set {0}=@Value where TableId=@TableId" I need to convert this query to a stored procedure. Is it possible at all? ...

Can I implement foreign keys in Entity Framework 4 at the entity layer?

I have a sizable legacy MS SQL database where foreign key relationships were never implemented. Is it possible to implement "logical" foreign keys between entities in Entity Framework 4 without there being actual foreign key relationships present in the database? ...

Searching in SQL Management Studio 2005

Is there a way to search for text within stored procedures? For example I want to find out if a particular table is being referenced by any stored procedure. ...

how to check the condition in sql server?

Table 1 slitem firstname lastname 1 aaa bbb Table 2 slitem firstname lastname 1 null null 2 null null Result : slitem firstname lastname 1 aaa bbb 2 null null i want to join this two table.... help me ...

In an OUTPUT clause in an INSTEAD OF INSERT trigger, is it possible to reference both INSERTED tables?

SQL Server 2005+ I have a view with an INSTEAD OF INSERT trigger. Inside the body of the trigger, I want to use a statement with an OUTPUT clause which references both INSERTED tables: the outer INSERTED table for the INSTEAD OF INSERT trigger the inner INSERTED table for the OUTPUT clause MSDN says this: If a statement that inc...

SQL Server: need to add a primary key

I have about 5000 records in a table in SQL Server 2008 I need to add a primary key. I don't care what it is, maybe an autonumber would be best? How do I add a primary key to every record ? I also would like this primary key to be generated automatically when I add new rows! ...

SQL Server 2008: How to Copy Data from Table in DB1 to Table in DB2?

I have two identical databases on the same server. During a deployment process, I have data in tables in database A that need copied over to the tables in database B. What is the easiest way to programmatically accomplish this task? EDIT: Tables do have identity columns. There are tables with foreign key constraints, so insert order i...

SQL Select Master Records and Display Number of Detail Records for Each

I have a Master and Detail table, the Detail linking to the Master record on a FK reference. I need to display all the data from the Master table, and the corresponding number of details for each record, i.e. MASTER TABLE ID Name Age 1 John 15 2 Jane 14 3 Joe 15 DETAIL MasterID Subjects 1 Trigonometry 1 Chemistr...

How can I prevent attacks on my SQL Server installation?

In the past month I've noticed in my event viewer on a sql server a lot of failure audits. Seems like a brute force attack from an ip in china trying to log in to the sa account which i have disabled. I've blocked it on my network firewall but then a week later i'm getting the same attack from another ip also based in china. So far i've ...

How to set the next job run time randomly in SQL Server 2000

Here is the scenario: We have a database in SQL Server 2000. The application that connects to this database randomly times out with different errors. We have run traces, but were not successful in catching the time out issue. Strangely, whenever we run the trace, the app does not time out. The plan is to setup a job to run traces. Cons...

sql-server: how do i know who is in my database?

i have an access front end and sql server backend. i would like to know which users are currently using the database. is this possible to do using access or sql-server? ...

will access disconnect from sql-server if it is idle?

i have multiple users connecting to sql-server-2008 database. i would like to know whether they will be disconnected if left idle? ...

Where is SSIS in Visual Studio 2010?

Where do I find the SSIS tools in Visual Studio 2010 Ultimate? I'm at a new job so new computer / new setup / new everything. I can't find them anywhere! Is there a specific edition of SQL Server that includes these tools? The DB is SQL Server 2005, SSMS is 2008, VS is 2010. ...

Parse column value based on delimeters

Here is a sample of my data: ABC*12345ABC BCD*234() CDE*3456789(&(& DEF*4567A*B*C Using SQL Server 2008 or SSIS, I need to parse this data and return the following result: 12345 234 3456789 4567 As you can see, the asterisk (*) is my first delimiter. The second "delimiter" (I use this term loosely) is when the sequence of numbers ST...

SQL statement joing Oracle and MS SQL Server

I never seen this, but is it possible to have one SQL call join data from Oracle and SQl Server? ...

creation of database through ODBC takes a very long time in sql server

i am exporting a datasheet from access into sql server 2008. it exports it fine, but it takes a very long amount of time for me to actually see it in SSMS. does anyone know why it takes so long? i dont know how long it takes because it's been about 10 minutes, but i do know that it was created since i was trying to export the same thing ...

Do I need to rebuild my SQL server database indexes?

I used the built-in performance tuning tool and built indexes for my database. Since then I changed some of the queries from "select top 10..." to "select top 50". My question is do I need to rebuild my SQL server database indexes? ...

Select non duplicate values from rows that are less than a specified number of minutes apart

I have a huge table with the following format: DATETIME NUMBER -------------------------------------- 2009-03-31 16:05:52.000 2453651622 2009-03-31 16:16:12.000 30206080 2009-03-31 16:16:16.000 16890039 2009-03-31 16:16:28.000 2452039696 2009-03-31 16:16:33.000 140851934 2009-03-31 16:16:51.000 245312...

90 days range using SQL server

Hi, is there a way in SQL server that i can count the items 90 days prior to the inception date and the items 90 days after the inception date. Example: select site, count(*) from mytable where date >=10/1/2009' and date <'12/30/2009' group by site 90 days before - after inception date. prior to inception date = 7/3/2009. inceptio...