sql

How to Architect an offline database

Using Sql Server 2008, .Net 3.5 & C#. I am designing a desktop application that runs in a read-only state when there is no internet connection. When the connection is available again it will use webservices to update the central DB. What technologies could I use to 'download' a set of data applicable to each client for use offline? ...

SELECT from SQL

I have a table which contains the names of a country, the population of the country and the countries GDP, how would I display the names of the country and their per capita GDP ...

How can I track which user has last modified the stored proc in sql server 2005+?

Inspired by this question How can I quickly identify most recently modified stored procedures in SQL Server I am wondering if at the same time we can identify the user? How to do this using sql program(if any possible)? I am eager to know. Thanks in advance ...

how to sum multiple sql queries together?

Hi! I'm trying to run multiple queries on multiple tables- similar to "select count(*) from TableA where x=1" per table. What I'd like to do, is get all of the count(*) values that are returned and sum them into a single value... Any ideas? ...

Filter SQL queries on the XML column using XPath/XQuery

I'm having a table with one XML column. I'd like to filter out the rows where a specific attribute in the XML match a string, essentially doing a WHERE or HAVING. The table looks something like this | id | xml | And the XML something similar to <xml> <info name="Foo"> <data .../> </info> <xml> I want to get all ids where ...

MySQL select from db efficiency and time-consumption

Which one of those will take the least amount of time? 1. q = 'SELECT * FROM table;' result = db->query(q) while(row = mysql_fetch_assoc(result)) { userName = row['userName']; userPassword = row['userPassword']; if (enteredN==userName && enteredP==userPassword) return true; return false; } 2. q = 'select * from table where userName=...

Using MySQL's "IN" function where the target is a column?

In a certain TABLE, I have a VARTEXT field which includes comma-separated values of country codes. The field is named cc_list. Typical entries look like the following: 'DE,US,IE,GB' 'IT,CA,US,FR,BE' Now given a country code, I want to be able to efficiently find which records include that country. Obviously there's no point in indexi...

Convert an array of integers for use in a SQL "IN" clause

Surely there is a framework method that given an array of integers, strings etc converts them into a list that can be used in a SQL "IN" clause? e.g. int[] values = {1,2,3}; would go to "(1,2,3)" ...

Truncate Table and UPDATE Statistics

Do we need to Update table statistics after calling Truncate table or it gets updated automatically? Q: Do we need to call "UPDATE STATISTICS" after truncating a table? ...

Rename foreign key system name in SQL Server Management Studio is failing

The method or operation is not permitted. I assume this is a permission's issue, but I can't figure out where I would change it. It is strange because I can rename an index with no issue. EDIT: If you're looking at a table, and you see "Columns, Keys, Constraints, etc.", this is under Keys, and it is the system name that I presu...

I wish I could correlate an "inline view"...

I have a Patient table: PatientId Admitted --------- --------------- 1 d/m/yy hh:mm:ss 2 d/m/yy hh:mm:ss 3 d/m/yy hh:mm:ss I have a PatientMeasurement table (0 to many): PatientId MeasurementId Recorded Value --------- ------------- --------------- ----- 1 A d/h/yy hh:mm:ss 100 1 A d/h/yy hh:mm:ss 200 1 ...

How do you fill in or pad a column with zeros with a MySQL query?

Hi there, I've got a large table (~10,000) and I need one column to take up exactly three spaces. It almost always only takes up one space, but I need the other two spaces to be filled in with zeros (it's an integer column). is there a function for that? ...

Limiting Access by Permission

Hi, thanks for viewing this. I have a db that has users, roles & user_roles. What I am trying to achieve is a login that will select users who have Admin or Associate permissions. The login then uses name and password to permit access. My SQL syntax thus far is - SELECT * FROM users LEFT JOIN ON user_roles ON user.id=user_roles.user...

Asking a Microsoft SQL Server database for the next auto-generated identifier on a table

I have a table in a SQL Server database that has an auto-generated integer primary key. Without inserting a record into the table, I need to query the database and get what the next auto-generated ID number will be. I think it's SQL Server version 2005, if that makes a difference. Is there a way to do this? ...

How do I set the default value for a column?

Note the table below. I am wanting to set the default value for the newly created BEST_SELLER column to "N". How do I go about doing that? Create Table Mystery (Book_Code Char(4) Primary Key, Title Varchar2(40), Publisher_Code Char(2), Price Number(4,2)) ...

TSQL: Cannot perform an aggregate function AVG on COUNT(*) to find busiest hours of day

Consider a SQL Server table that holds log data. The important parts are: CREATE TABLE [dbo].[CustomerLog]( [ID] [int] IDENTITY(1,1) NOT NULL, [CustID] [int] NOT NULL, [VisitDate] [datetime] NOT NULL, CONSTRAINT [PK_CustomerLog] PRIMARY KEY CLUSTERED ([ID] ASC)) ON [PRIMARY] The query here is around finding the distributi...

SQL Distinct Grouping?

Here is my query: SELECT dbo.EmailCampaignTracking.emailOpened, dbo.EmailCampaignTracking.emailUnsubscribed, dbo.EmailCampaignTracking.emailBounced, COUNT(*) FROM dbo.EmailCampaignTracking Group By dbo.EmailCampaignTracking.emailBounced, dbo.EmailCampaignTracking.emailUnsubscribed, dbo.EmailCampaignTracking.emailOpene...

Need some help with SQL GroupBY

I have a two column table as follows: ID Emp ID 1 1 1 2 1 3 1 4 2 2 2 6 2 10 3 1 3 5 4 8 5 2 5 6 I need something like this: ID Emp ID 1 1,2,3,4 2 2,6,10 3 1,5 4 8 5 2,6 Please help :) ...

how to get the Id of last row deleted from SQL table

I am trying to get the last Id using max(Id) function where Id is the primary key. My code works well unless I delete last row from the table, because when I delete last row then that Id is still preserved and in that case max(Id) will retrieve the last row Id but not that Id which is deleted from the table. Is there any function which ...

SQL "*=" operator

Possible Duplicate: Transact-SQL shorthand join syntax? I ran across a T-SQL script that does something like this in the where clause: ... where o.obj_code *= c.prv_code I can't seem to find any documentation on the *= operator. Can anyone explain its use and maybe point to some documentation on it? Is this specific to T-SQ...