sql

How to add 'ON DELETE CASCADE' in ALTER TABLE statement

I have a foreign key constraint in my table, I want to add ON DELETE CASCADE to it. I have tried this: alter table child_table_name modify constraint fk_name foreign key (child_column_name) references parent_table_name (parent_column_name) on delete cascade; Doesn't work. EDIT: Foreign key already exists, there are data in fo...

SSIS Package runs from Windows, but fails when run from SQL Agent jobs

I have a SSIS package (exports some database tables --> CSV file) After creation of this package, I can run the package from Visual Studio or just by clicking it. But it fails if i add to execute this package as a SQL Agent Job scheduled at some arbitrary time of a day. Pointers needed if i have to configure anything related to Permi...

Degraded performance of a query after adding Index

Hi, I have a query which part of a SP which is executed fairly regularly, and the query took a while to execute, so I decided to have a look at it. I did an autotrace on the query, and this was the execution plan returned [ pasted in pastebin due to excessive size ] I added indexes on the tables which was undergoing full table access,...

Where can I get a simple table of time zones for use in SQL server?

I just need to make a SQL table of time zones - at this point, my only need is to populate a drop-down list on an online form. I'm envisioning something simple with columns for ISO code, name, UTC offset, and perhaps a list of representative cities. I thought I would be able to easily find something online to copy-and-paste, but haven't ...

What are the performance implications of using 'Using' on sqlConnections

I came across an article saying that using my sqlConnection like this : using (SqlConnection sqlConnection = new SqlConnection(Config.getConnectionString())) { using (SqlDataAdapter dataAdapter = new SqlDataAdapter(query, sqlConnection)) { dataAdapter.Fill(dataSet); ...

How do I move the Transaction Log for a database using sqlcmd/command line?

Hi, I need to move the transaction log for a database I have just created using aspnet_regsql. Is it possible to move the transaction log using sqlcmd or any other command line tool? kind regards, ...

Check for a substring in a string in Oracle without LIKE

How can I check for a substring in a string in Oracle without using LIKE? Let's say I want to select all users from a table that have the letter "z" in their last name: SELECT * FROM users WHERE last_name LIKE "%z%"; That would work, but I don't want to use LIKE. Is there some other function I could use? ...

Logic in stored procedure

I have need of some logic in a stored procedure. All the stored procedure does it perform a couple of logic rules and then returns a true or false depending on the result. The pseudo SQL code: CREATE TABLE #PV ([Date] DATETIME, Dis FLOAT, Del Float, Sold Float) INSERT #PV exec GetPVSummaryReport @ID, @PID, @From, @To SELECT AVG(Dis) / ...

How do I test a Table-Valued Function in SQL Server Management Studio?

I've never worked with Database Functions, but my current project requires it. I need to put a common sql query into a function so we don't have to type it out in our code hundreds of times. I've got the function created, but I don't know how to use it. Here's the function code: USE [DB_NAME] GO SET ANSI_NULLS ON GO SET QUOTED_IDENT...

Can you have magic numbers in Access 2007?

How do I store numbers in an Access column and then associate some meaningful string to each value? Because I don't want to be seeing raw numbers when I can define the meaning of each value once at for all, and have those meanings displayed in the Datasheet View, like: ID Name Type 1 Jack 1 (Friend) 2 Jill 1 (Frien...

FullText Search using multiple tables in SQL

Hi there. I have 3 tables, tblBook(BookID, ISBN, Title, Summary) tblAuthor(AuthorID, FullName) tblBookAuthor(BookAuthorID, BookID, AuthorID) tblBookAuthor allows for a single book to have multiple authors and an author may have written any number of books. I am using full text search to search for ranking base on a word: SET @Word ...

Find the size of OLE/binary data in MSAccess DB

I am trying to find a function in MSAccess that can be used to return the size of data (in bytes). e.g something like SELECT x.id, sizeof(x.custom_data) AS size Specifically for OLE data types but anything more general would be cool. ...

Avg of a Sum in one query

I would like to know if I can get the average of a sum in one single SQL SERVER request, Have tried to do it with the following request but it doesn't work: SELECT t.client, AVG(SUM(t.asset)) AS Expr1 FROM TABLE t GROUP BY t.client ...

Clear/ Reset Resource Provider

How do you get access to the Resource Provider for the current context? I have a web page that allows a client to edit their Globalization values which are stored in SQL. However pages still utilize the cached values until the app domain is freed. How can I force clear/reset the provider and or get access to it to clear its cache. Th...

sql: BETWEEN v1 AND v2

Is there a difference in the order of v1 and v2 in a BETWEEN query on SQL Server? SELECT * FROM table WHERE col BETWEEN v1 AND v2 currently I don’t get any results if v1 is bigger than v2. Is this only syntactic sugar for col >= v1 AND col <= v2 or does it really take all values between the two? on my current observations I gues...

return column values as IEnumerable

I have this code working: public IEnumerable<string> GetEmpNames() { var cmd = SqlCommand("select [EmpName] from [dbo].[Emp]"); using (var rdr = cmd.ExecuteReader()) while (rdr.Read()) yield return (string) rdr["EmpName"]; } However, I'm wondering if there's a better (LINQish) way, not having to resort to y...

SQL - Converting 24-hour ("military") time (2145) to "AM/PM time" (9:45 pm)

I have 2 fields I'm working with that are stored as smallint military structured times. Edit I'm running on IBM Informix Dynamic Server Version 10.00.FC9 beg_tm and end_tm Sample values beg_tm 545 end_tm 815 beg_tm 1245 end_tm 1330 Sample output beg_tm 5:45 am end_tm 8:15 am beg_tm 12:45 pm end_tm 1:30 pm I had...

put names in table into arraylist??

i have 5 names in a table and i need to put these in an arraylist.... any suggestions??? int rowsinmachgrp = getnumofrows();//gets no of rows in table SqlConnection dataConnection = new SqlConnection(); dataConnection.ConnectionString = ConfigurationManager.ConnectionStrings["SumooHAgentDBConnectio...

mysql - fill field by other fields

I have a birthdate, year, month, day columns where columns "year,month,day" are foreign key to other tables What I want to do is for each birthdate get id(year(birthdate)) to be the value of year column and the same thing for month and day columns. How can I do this in MySQL? Thanks in advance ...

What is the proper name for this table schema?

We have a common database schema that we use for some tables in our system. Them main reason is that we are running a multi-tenant database so not all of our users require the same fields. However, I do not know what the 'proper' name for this type of schema is. Here's an example of what one of our tables might look like: ClientID |...