sql

How do you run a 300mb+ MS SQL .sql file?

I use RedGate SQL data compare and generate a .sql file so i can run it on my local machine but the problem is the file is over 300mb and i can't do copy and paste because the clipboard won't able to handle it and when i try to open the file in sql management tool. it give me error compiling about the size. is there a way to run large ....

Why would @@IDENTITY or SCOPE_IDENTITY() be DBNull?

(resolved: see bottom) I have the following code snippet: Protected Sub SqlDataSource1_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles SqlDataSource1.Inserted affected = CInt(DirectCast(e.Command.Parameters("@affected"), IDbDataParameter).Value) newID = CInt(DirectCas...

Data Modeling: What is a good relational design when a table has several foreign key constrainst to a single table?

Hi there! I have 2 tables: 1. Employees 2. Vouchers Employees table has a single primary key. Vouchers table has 3 foreign key constraints referencing the Employees table. The following is a sample T-SQL script (not the actual table script) to create both tables and their relationship in SQL Server: IF OBJECT_ID('dbo.Vouchers') IS N...

What would be a good way to add "friendly" column names to a LINQ to SQL model?

I have a LINQ to SQL model setup - however in my app there are certain places where I want "friendly" column names for example: "NameFirst" to be "First Name" "AgencyName" to be "Agency" Just looking for suggestions on where the best place/technique to create these mappings would be - without changing the model. These mappings won't ne...

Quick SQL Question: SQLzoo tutorial problem

Problem 2b goes as follows: 2b. For each subject show the first year that the prize was awarded. nobel(yr, subject, winner) My solution was this: SELECT DISTINCT subject, yr FROM nobel ORDER BY yr ASC; Why isn't this working? ...

How can I select rows that are null using bound queries in Perl's DBI?

I want to be able to pass something into an SQL query to determine if I want to select only the ones where a certain column is null. If I was just building a query string instead of using bound variables, I'd do something like if ($search_undeleted_only) { $sqlString .= " AND deleted_on IS NULL"; } but I want to use bound que...

How to export a DB2 database without a DB2 server

I have a db2 database file, but do not have a db2 server. I would like to export this data into something else (e.g. SQL, but it doesn't really matter what), without having to setup a full db2 server (I started looking into this, but it seems very involved). Ideally the tool would run on (Debian) Linux, but Windows/OS X is fine if nece...

Optimized Table structure for Tags table.

Consider these 3 table structures. Which will perform these queries the best. Structure 1 - TagID as int with a join table Article ------- ArticleID int Article_Tag ------------ ArticleTagID int ArticleID int TagID int Tag --- TagID int TagText varchar(50) Structure 2 - Tags only in Join table as string Article ------- articleID i...

In SQL is there a difference between count(*) and count(<fieldname>)

Pretty self explanatory question. Is there any reason to use one or the other? ...

SQL JOIN help

SELECT * FROM friends WHERE (user1 = $userid OR user2 = $userid) AND accepted = 1 how would a JOIN look like if i want to get lets say user2's information from table "users"? table friends: id int(11) NOT NULL auto_increment, user1 int(11) NOT NULL, user2 int(11) NOT NULL, date datetime NOT NULL, accept tinyint(1) NOT NULL, ...

Do SQL Views retain relationship information in terms of performance?

Consider the tables: (-> denotes a SQL defined relationship) USER (userid, username, imageid->IMAGE.imageid) EVENT (eventid, userid->USER.userid, description) IMAGE (imageid, location) Say I have a view (let's call it vw_UserInfo) defined as the following query. SELECT u.*, i.* FROM users u INNER JOIN images i ON i.imageid = u.imagei...

SQL tutorial question: Listing the first value from a three-way joined table query

Ugh ok I'm terrible at explaining things, so I'll just give you the quotes and links first: Problem 4b (near bottom): 4b. List the film title and the leading actor for all of 'Julie Andrews' films. movie(id, title, yr, score, votes, director) actor(id, name) casting(movieid, actorid, ord) (Note: movie.id = cast...

What simple guidelines would you give your developers for writing good SQL against Oracle?

I work in a group of about 25 developers. I'm responsible for coming up with the database design (tables, views, etc) and am called apon for performance tuning when necessary. There are a couple of different applications that connect. Database access is via JDBC, hibernate, and iBatis SQL maps. Developers with various levels of exper...

Another SQL tutorial question: Field > 0?

Alright, this one (3a; sample problem with provided answer) has got me scratching my head: bbc(name, region, area, population, gdp) 3a. Find the largest country in each region: SELECT region, name, population FROM bbc x WHERE population >= ALL (SELECT population FROM bbc y WHERE y.region = x.region AND...

How slow is DISTINCT?

I have the option of writing two different formats for a database structure: Article ------- ArticleID int FK Article_Tags ------------ ArticleTagID int FK ArticleID int FK TagText varchar(50) or Article ------- ArticleID int PK Article_Tags ------------ ArticleTagID int PK ArticleID int FK TagText varchar(50) FK Tag --- TagText v...

MySQL Query - getting missing records when using group-by

I have a query : select score, count(1) as 'NumStudents' from testresults where testid = 'mytestid' group by score order by score where testresults table contains the performances of students in a test. A sample result looks like the following, assuming maximum marks of the test is 10. score, NumStudents 0 10 1 20 2 12 3...

Access sharepoint list data in SQL

I am new to sharepoint development. I have a list, this list has a column that is called Todaysdate, this column needs to be updated daily to todays accual date and since it contains ~20,000 rows I am NOT going to update it manually everyday. Because it's used in a calculation row. My question is can I just use SQL and update the rows...

SQL Join maybe?

$query = mysql_query("SELECT * FROM news WHERE id = '{$_GET['id']}'"); $news = mysql_fetch_assoc($query); $sql84 = mysql_query("SELECT username FROM users WHERE id = '".$news['user_id']."'") or exit(mysql_error()); $author = mysql_fetch_array($sql84); is there i better way of doing this? a join maybe? how that look ...

sql to detect fields modified in update trigger ( sql server 2005 )?

In sql server 2005 , inside an update trigger is there a way to find the list of fields\columns those are modified by the original update query. I have a table with 150 columns and inside the trigger need to konw if ONLY one particular field was updated or not ( and no-other field was modified ) I can write a long sql to compare 150 c...

Mirroring vs Replication

How to decide whether to choose a Replication or Mirroring in SQL Server 2005 to provide data availabilty and performance at the same time. ...