sql

SQL Server Batch Error Handling Problem.

How do I get this batch of SQL to get to the RollBack Transaction part at the end? SQL just stops halts script execution on the bad line of code. I know I can use a try/catch construct but i'm more interested in how this was this handled before SQL added try/catch. BEGIN TRAN CREATE TABLE TempTable (c1 INT NULL) INSERT INTO TempTable ...

DOM libraries in .Net for building SQL statements

Are there any libraries for .Net for building sql statements? (BTW I know about ADO.NET SqlCommand, SqlParameter classes already) I'm currently developing a library to do this but am now wondering if there is already something out there which might be better. Edit: At this point I'm only interested in returning a DataTable object as...

Foreign key refering to primary keys across multiple tables?

Hi! I have to two tables namely employees_ce and employees_sn under the database employees. They both have their respective unique primary key columns. I have another table called deductions, whose foreign key column I want to reference to primary keys of employees_ce as well as employees_sn. Is this possible? for example employee...

In which scenario would you prefeer to use mysql over sql server or viceversa?

In which pratical scenarion would you prefeer one or the other? I know there are a lot of parameter you can compare, can you give me some practical examples? Example: mysql in case of multiple databases with few tables, sql server for single database with lots of tables because.... ...

Largest text usable variable in MSSQL 2005 Stored Procedure?

What is the largest size text usable variable in a MSSQL Stored Procedure. I'm seeing that largest size you can use is a varchar(8000). We can use ntext, text, etc. So does it require stitching varchars together? What about if I used a CLR Stored Procedure?? ...

How to fetch 3 first places of each game from the score table in mysql?

hi I have the following table: CREATE TABLE `score` ( `score_id` int(10) unsigned NOT NULL auto_increment, `user_id` int(10) unsigned NOT NULL, `game_id` int(10) unsigned NOT NULL, `thescore` bigint(20) unsigned NOT NULL, `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP, PRIMARY KEY (`score_i...

Data source controls and parameter type conversion

Hello, Q1 - In the code example below runtime converts a value between two incompatible types: <SelectParameters> <asp:Parameter Name="City" Type="Int32" /> </SelectParameters> protected void SqlDataSource2_Selecting(object sender, SqlDataSourceSelectingEventArgs e) {e.Command.Parameters["@City"].Value = "100";} Except...

How should I approach migrating data from a "bad" database design to a usable design?

The current project I inherited mainly revolves around one unnormalized table. There are some attempts at normalization but the necessary constraints weren't put in place. Example: In the Project table, there is a client name (among other values) and there is also a clients table which just contains client names [no keys anywhere]. T...

Consecutive SQL statements with state

I'm writing a simple messaging program, where there is a table of messages, which can be claimed by users and have stuff done to them by that user. It isn't predestined which user will claim a given message and so I want a query to select the first of all the available messages, which I have, and then one to mark that message as take, wh...

Will Ado.net pass to a stored procedure just the value or also the type?

hello, <asp:SqlDataSource ID="sourceEmployees" runat="server" ProviderName="System.Data.SqlClient" ConnectionString="<%$ ConnectionStrings:Northwind %>" SelectCommand="SELECT EmployeeID, FirstName,LastName, Title, City FROM Employees WHERE City=@City"> <SelectParameters> <asp:Parameter Name="Cit...

ConvertEmptyStringToNull property

Hello, A) public void GetEmployee( int EmployeeID ); <asp:ObjectDataSource SelectMethod=”GetEmployee” …> <SelectParameters> <asp:ControlParameter Name = ”EmployeeID” ...> </SelectParameters> If for whatever reason EmployeeID parameter is NULL, ObjectDataSource will convert Null to zero and passed it as argument to GetEmpl...

System.Data.Sqlite FormatException using a parameter with LIKE

I'm using Sqlite as my database of choice in a C# forms app, with http://sqlite.phxsoftware.com/ System.Data.SQLite provider. I'm trying to implement a search function, but it's not playing nice... or I'm missing something. The simplified sql I'm using looks like this: SELECT * FROM Table WHERE column LIKE @boundParameter ESCAPE '!' ...

& operator in a SQL Server WHERE Clause

Sorry for the very basic question. What does the & operator do in this SQL WHERE (sc.Attributes & 1) = 0 sc is an alias for a table which contains a column attributes. I'm trying to understand some SQL in a report and that line is making it return 0 entries. If I comment it out it works. I have limited SQL knowledge and I'm not sure ...

SQL query - how to fetch non-read messages efficiently

How do I best gather messages that have not been read by a given user? Existing tables Message table ---------------------------------- id title body sentAt User table ---------------------------------- id username Read Messages table ---------------------------------- user_id message_id I'm thinking something like ...

Large volume database updates with an ORM

I like ORM tools, but I have often thought that for large updates (thousands of rows), it seems inefficient to load, update and save when something like UPDATE [table] set [column] = [value] WHERE [predicate] would give much better performance. However, assuming one wanted to go down this route for performance reasons, how would you ...

Reusing SqlCommand ?

I am not really sure if it is possible or not. I am currently working on the college project and i have a function that uses stored procedure. I would like to know if it is possible to take same SqlCommant apply updated parameters and call to the stored procedure again withing same function. Lets say i have something like that in my cod...

How can I get rid of dynamic SQL

I have the following dynamic SQL in one of my package bodies OPEN ccur for 'select c.category from test_category c where c.deptid='||PI_N_Dept || ' and c.category not in ('|| sExcludeCategories ||')'; sExcludeCategories will contain a set of integers separated by comma. I would like to eliminate this dynamic SQL ...

Dropping unnamed constraints

Being a rookie, I've created some foreign keys without an explicit name. Then i've founded SQL generated crazy names like FK__Machines__IdArt__760D22A7. Guess they will be generated with different names at different servers. Is there any nice function to drop the unnamed FK constraints passing as arguments the tables and the fields in...

Performance of inner join compared to cross join

The effect of issuing an inner join is the same as stating a cross join with the join condition in the WHERE-clause. I noticed that many people in my company use cross joins, where I would use inner joins. I didn't notice any significant performance gain after changing some of these queries and was wondering if it was just a coincidence ...

Rails ActiveRecord: Inserting text containing unprintable/weird characters

I am inserting some text from scraped web into my database. some of the fields in the string have unprintable/weird characters. For example, if text is "C__O__?__P__L__E__T__E", then the text in the database is stored only as "C__O__" I know about h(), strip_tags()... sanitize, ... etc etc. But I do not want to sanitize this SQL. Th...