sql

Is it possible to enforce Read Only behaviour with SqlCommand?

Is it possible to enforce read only permissions using the System.Data.SqlClient code accessing a Sql Server database? I want to allow trusted users to write their own SELECT statements, in a web site. NO Im not trolling here! Obvious solutions are to create a readonly user in the database, and use those credentials in the connection st...

Using PHP to upload an image and store data in MSSQL

Hi there, I'm attempting to upload an image as well as add details such as; title, description and filepath into a database table. I'm using the following code, but it isn't adding any data to the database; (The session.php include contains the database connectivity.) <?php include('includes/session.php'); $uploadDir = 'submitted/pic...

Oracle comparison issue

I'm trying to compare two columns from different columns. Ex: Select a.Col1, b.Col1, CASE WHEN a.Col1 <> b.Col1 THEN 'TRUE' ELSE 'FALSE' END CASE FROM TableA a LEFT OUTER JOIN TableB b ON a.id = b.id I always get false but not true even though they are different or if there is a value in TableA and not in TableB. What is wrong with ...

How to read data from an XML file and store it into database (MySQL)?

I need to get data from an XML file and store it into a MySQL Database. I am thinking of using a SAX Parser for parsing the data but I am not sure of how to store data efficiently into database, I am thinking of few technologies like JDBC and Hibernate but I wanted to ask about what would be the efficient way of doing it? Note: Here pro...

Tricky SQL query

Hello guys! Really tricky SQL statement I have here. Trying to build this query for about hour. Maybe You can help me. We have a table with 3 columns: gamename | user | times_played The query should select top three games (depending total times_played) and top three user who has played most times in this game => 9 rows. The result is...

Database: SQL Pagination ?

I'm using MySQL. I want to limit the amount of rows fetched from the database. I have a SQL statement that returns 10,000 records which are all relevant to the search. SELECT colA, colB, colC FROM xyzTable WHERE ... ORDER BY colA I know how to use the TOP statement to return the TOP x number of rows fetched but how do I fetch rows r...

Three potential db designs

I've been considering three similar database designs, but haven't come up with a very strong for or against regarding any of them. One huge table for content content: int id, enum type, int parent_id, varchar title, text body, text data This would assign each row a type (news, blog, etc), and have fields for common/standard/searchab...

Mysql Adding column and Foreign keys

In mysql, can I add a column and foreign key in the same statement? And what is the proper syntax for adding the fk? Here is my SQL: ALTER TABLE database.table ADD COLUMN columnname INT DEFAULT(1), FOREIGN KEY (fk_name) REFERENCES reftable(refcolumn) ON DELETE CASCADE; ...and the accompanying error message: You have an error i...

Database: SQL Pagination - How many pages?

I'm using MySQL LIMIT to display 50 rows (pages) at a time, like so: SELECT cols FROM table LIMIT 49, 50 What's the most efficient way for me to determine how many "pages" I have in my result set (how many total records my query is producing)? Before I run the code above, should I just run a quick and dirty: SELECT COUNT(cols) FROM ...

MySQL - Query All users WITHOUT an appointment

If I have two tables: Users and Appointments. How would I query the db to find something like the following: SELECT * FROM users WHERE (none of: appointments.user = user.id) I am assuming I would need some type of join with the appointments table, just not sure where to start. ...

SELECT statement for the "length" of the field is greater than 1

I have an LINK field in my table. Some rows have a link, some don't. I'd like to select all rows where LINK is present. (length is greater than X characters). How to write this? ...

how do I make a composite key with SQL Server Management Studio?

how do I make a composite key with SQL Server Management Studio? I want two INT columns to form the identity (unique) for a table ...

I want to show records from a table having a date column from sqldatabase in dates order. How should I?

I want to show records from a table having a date column from sqldatabase in dates order. How should I? ...

MySQL performance using IN predicate

If I run the following queries each one returns quickly (0.01 sec) and gives me my desired result. SELECT tagId FROM tag WHERE name='programming' SELECT COUNT(DISTINCT workcode) FROM worktag WHERE tagId=123 OR tagId=124 (assume the two tagId numbers were the results from the first query) I would like to combine these queries so I onl...

How to query for err in MySQL?

I added a column to my table that does not allow null. I guess that is why some of my rows now have real values in the column but some other rows now have (err) in the column. How can I query for this? select * from Table where new_column = err That doesn't work. ...

SQL ORDER BY date problem

Can you please help me in solving this problem. I am trying to order the results of an SQL query by date, but I'm not getting the results I need. The query I'm using is: SELECT date FROM tbemp ORDER BY date ASC Results are: 01/02/2009 03/01/2009 04/06/2009 05/03/2009 06/12/2008 07/02/2009 Results should be: 06/12/2008 03/01/2009 ...

SQL Super Search

Does anyone have a good method for searching an entire database for a given value? I have a specific string I'm looking for, it's in TableA, and it's also a FK to some other table, TableB, except I don't know which table/column that is. Assuming there's a jillion tables and I don't want to look through them all, and maybe will have to d...

.Net and SQL Server Diagnostics

Our company has many .Net applications on many servers which utilize many different SQL Servers. We do not have a clear idea of what is using what. It would be great to get a full picture of what's going on down to the smallest details. Especially important is to know what App is connecting to what Database. Idea's so far have been to a...

SQL Query to retrieve results from two equally designed tables

How can I query the results of two equally designed tables? if table1 contains 1 column with data: abc def hjj and table2 contains 1 column with data: uyy iuu pol then i want my query to return abc def hjj uyy iuu pol but I want to make sure that if I try to do the same task with multiple columns that the associations ...

SqlBulkCopy into table with composite primary key

I'm trying to use SqlBulkCopy to insert new rows into my DB table by manually populating a DataTable w/in my application. This works fine for all tables except the table that has a composite primary key made up of 3 columns. Whenever I try to SqlBulkCopy anything into this table, I get the following error: Violation of PRIMARY KEY con...