sql

SQL Server 2005 - how to shrink the tempdb

Hi, My tempdb size is growing too much, as we are doing too many transactions in the database. Can someone let me know how to shrink this tempdb without restarting the server. I have tried DBCC SHRINKDATABASE and it didn't help Thanks in advance ...

Optimise SQL query joined on DATE(datetime) = date?

I have two tables: one has a datetime column, the other has a date column. I want to join the two tables like this: SELECT t1.dt, t2.d FROM table1 t1, JOIN table2 t2 ON DATE(t1.dt) = t2.date But obviously, this kills the index on t1.dt. What's the best strategy to get around this? The simplest approach would be to add a ne...

(Mysql) How to mark different WHERE OR rows?

For example i have requested: WHERE (friend_id=? OR client_id=?) How do i know which row meets friend_id condition and which meets client_id condition? Is it possible to mark/flag rows depending of meeting condition somehow? Thanks. ...

What's the standard practice for naming an intermediary table in SQL?

I have a table called Product and a table called Shop. Each shop has a list of Products that it sells. I need an intermediate table that has ShopID and ProductID in it. What should I call that table? My mind has drawn a blank. ShopProducts? Edit: Perhaps I should call it "ShopAvailableProducts"? Or is that too confusing. ...

How to select the first continous group of rows using Oracle SQL

Hi All, I have the following data: Date             GroupID     Value 1/01/2000    1                 44 2/01/2000    1                 55 3/01/2000    1                 66 4/01/2000    2                 77 5/01/2000    2                 88 6/01/2000    1                 99 7/01/2000    1                 22 I am looking for a query cap...

Replace IN with EXISTS or COUNT. How to do it. What is missing here ?

I am using IN keyword in the query in the middle of a section. Since I am using nested query and want to replace In with Exists due to performance issues that my seniors have told me might arise. Am I missing some column, what you are looking for in this query. This query contain some aliases for readibility. How can I remove it. S...

Should I use .NET (System.Net.Mail) to batch send my web application's emails or SQL (msdb.sp_send_dbmail)?

Scenario: 1) My application is a .NET 3.5 C# web app and the database is SQL 2008. 2) Emails will be in the region of 100 to 1000 a day and are triggered by various web user interactions with the app. 3) Most emails will contain attachment(s) between 50KB and 5MB. Some emails will be HTML and some will be plain text. 4) All attachmen...

Excel Macro to Generate SQL From Sparsely Populated Sheet?

I have a worksheet that has been sparsely populated with data that needs to go into several relational database tables. The sheet looks like this: A B C D E F G Table_1 Table_2 Table_2 Table_3 Table_3 Table_3 Table_3 Table_3 Table_3 Table_3 Table_3 Ta...

How to use UUIDs but remain compatible to existing DB ids?

Hi, we are currently designing an API for our product. The API offers access to a graph consisting of relations between types, such as users, posts or the like. Now, those objects are referenced by primary key id in our database, but since every object is in a different table, those ids collide without the information of the type of ob...

SQL - Converting char to exact length varchar

I am trying to do something like this: SELECT CAST(MYCHARCOL AS VARCHAR(LEN(MYCHARCOL))) FROM MYTABLE How do I convert a char column to varchar that is the exact length of the data inside that char column? ...

SQL QUERY showing Between Dates as specific dates + Data belonging to each date!

This is how a table is presented SELECT RequestsID, Country, Activity, [People needed (each day)], [Start date], [End date] FROM dbo.Requests There will be a lot of requests, and I would like to sum up the "People needed" per day (!), not as Between Start- and End date. Also I would like to group by country, and have the possibility ...

am i looking for average here

Hi All, I have a note field that I'm trying to determine a cut off length to display. I have some numbers Note Length and # of Notes with that length How do I come up with a good average? Do I need more information? Thanks, rod. ...

name of tables & views in stored procedure in sql server 2005

Hi All, I have a stored procedure, I want to know the name of the tables and views use in that stored procedure, can any one suggest how can I do so. Thanks in advance. ...

Complicated SQL Join Query

Hello, i have two tables one of is users: id int(11) NO PRI NULL auto_increment membership_type tinyint(3) unsigned NO MUL NULL username varchar(16) NO NULL password char(40) NO NULL email varchar(100) NO NULL firstname varchar(40) NO NULL ...

SQL Server Stored Procedure with CHAR parm

This one DOES NOT work fine: ALTER PROCEDURE rconte.spPesquisaPesIdDadoCodigo24 ( @pPesCodigo24 char ) AS SELECT pesId FROM tblPesquisas where pesIdentificadorRandomico24ParaEmail = @pPesCodigo24 RETURN This one WORKS FINE: ALTER PROCEDURE rconte.spPesquisaPesIdDadoCodigo24 ( @pPesCodigo24 char(24) ...

Have Oracle automatically roll back abandoned sessions?

Is there any way to guarantee that an application won't fail to release row locks in Oracle? If I make sure to put commit statements in finally blocks, that handles the case of unexpected errors, but what if the app process just suddenly dies before it commits (or someone kicks the power cord / lan cable out). Is there a way to have Ora...

querying for user's ranking in one-to-many tables

I am trying to write a query to find the score rank of a user's games. I need it to take in a user id and then return that user's relative ranking to other user's scores. There is a user and a game table. The game table has a userId field with a one-to-many relationship. Sample table: users: id freebee 1 10 2...

script to autoupdate IP in config file

Problem I have a SQL server that has a dynamic IP address. However I have a url e.g. 'mydynamic.com' which is automatically updated to the current IP of the SQL server Requirement I need a script (vb/bat) that can take this URL and resolves the IP. Then take a config file and replace a placeholder with that IP. The idea is that the co...

Creating migration scripts from the legacy model to the current one (being under development)

Originally, the model (including tables, views, packages, etc.) was built from the DML scripts (generated by TOAD). The scripts look like: DROP TABLE TABLESPACE.TABLENAME CASCADE CONSTRAINTS; CREATE TABLE TABLESPACE.TABLENAME ... Over time the model has changed - I've added new columns to the tables, altered some vews, added new metho...

Nhibernate : is it possible to make HQL generate SQL query with JOIN

Hello everybody This is my problem. I have a many-to-one relationship from a accountlist to a client When i want to list accounts with client name, my HQL query ("From accountlist") generates thousands SQL queries, one for the accountlist and one for each client. Is it possible, with HQL to force to make juste one sql request with a j...