HI,
Currently i have one big datacontex with 35 tables (i dragged all my DB tables to the designer). I must admit it is very comfortable cause i have ORM to my full DB and query with linq is easy and simple.
My questions are:
1. Would you consider it bad design to have one datacontext with 35 tables or should i split it to logic units?
2. Is there any performance penalties for using such a big datacontext?
Thanks, Pini.
Hi All,
Am having columns as category and songs in my table for each category there are almost 10 songs and in total there are 7 category such that which was tabled as
category1 songCategory1a
category1 songCategory1b
category1 songCategory1c
---
category2 songCategory2a
category2 songCategory2b
category2 songCategory2c
---
category3 songCategory3a
category3 songCategory3b
category3 songCategory3c
---
like that there is table in that i want to get the result as
category1
category2
category3
category4
kindly any one help me ,
i tried
(from s in _context.db_songs
select new { s.Song_Name, s.Song_Category }).Distinct().ToList(); but it didnt work its resulting as such.
i have a table with 6 fields. the columns are ID, new_id price,title,Img,Active. I have datawhich is duplicated for the price column.
When I do a select i want to show only distinct rows where new_id is not the same.
e.g.-
ID New_ID Price Title Img Active
1 1 20.00 PA-1 0X4... 1
2 1 10.00 PA-10 0X4... 1
3 3 20.00 PA-11 0X4... 1
4 4 30.00 PA-5 0X4... 1
5 9 20.00 PA-99A 0X4... 1
6 3 50.00 PA-55 0X4... 1
When the select statement runs, only rows with ID (1,4,9,6) should show. Reason being the new_ID with the higher price should show up.
How can i do this?
I have a simple query that relies on two full-text indexed tables, but it runs extremely slow when I have the CONTAINS combined with any additional OR search. As seen in the execution plan, the two full text searches crush the performance. If I query with just 1 of the CONTAINS, or neither, the query is sub-second, but the moment you add OR into the mix the query becomes ill-fated.
The two tables are nothing special, they're not overly wide (42 cols in one, 21 in the other; maybe 10 cols are FT indexed in each) or even contain very many records (36k recs in the biggest of the two).
I was able to solve the performance by splitting the two CONTAINS searches into their own SELECT queries and then UNION the three together. Is this UNION workaround my only hope?
Thanks.
SELECT a.CollectionID
FROM collections a
INNER JOIN determinations b ON a.CollectionID = b.CollectionID
WHERE a.CollrTeam_Text LIKE '%fa%'
OR CONTAINS(a.*, '"*fa*"')
OR CONTAINS(b.*, '"*fa*"')
Execution Plan (guess I need more reputation before I can post the image):
I'm trying to rename the columns. The syntax should be the column name between double quotes incase of two words, like this:
SELECT p_Name "Product Name" from items
So I'm trying to do it in C# code like this:
string sqlqry1 = "SELECT p_Name \"Prodcut Name\" from items";
But I get an error:
Syntax error (missing operator) in query expression 'p_Name "Prodcut Name"'.
It seems am having somthing wrong with the quotes, but I can't figure out.
I am adding a new GUID/Uniqueidentifier column to my table.
ALTER TABLE table_name
ADD VersionNumber UNIQUEIDENTIFIER UNIQUE NOT NULL DEFAULT NEWSEQUENTIALID()
GO
And when ever a record is updated in the table, I would want to update this column "VersionNumber". So I create a new trigger
CREATE TRIGGER [DBO].[TR_TABLE_NAMWE]
ON [DBO].[TABLE_NAME]
AFTER UPDATE
AS
BEGIN
UPDATE TABLE_NAME
SET VERSIONNUMBER=NEWSEQUENTIALID()
FROM TABLE_NAME D
JOIN INSERTED I ON D.ID=I.ID/* some ID which is used to join*/
END
GO
But just realized that NEWSEQUENTIALID() can only be used with CREATE TABLE or ALTER TABLE. I got this error
The newsequentialid() built-in function can only be used in a DEFAULT expression for a column of type 'uniqueidentifier' in a CREATE TABLE or ALTER TABLE statement. It cannot be combined with other operators to form a complex scalar expression.
Is there a workaround for this ?
Edit1: Changing NEWSEQUENTIALID() to NEWID() in the trigger solves this, but I am indexing this column and using NEWID() would be sub-optimal
I am adding a simple web-interface to show data from a commercial off the shelf (COTS) application. This COTS issues locks on any record the user is actively looking at (whether they intend to edit and update it or not).
I have found sp_lock and the Microsoft sp_lock2 scripts and can see the locks, so that's all well and good.
However, I cannot figure out how I can tell if a specific record I am about to update has been affected by one of these locks. If I submit the update request and there is in fact a lock, the web-interface will wait indefinitely until the user closes the window in the COTS.
How can I either:
a) determine before issuing an update that the record has been locked
OR
b) issue an update that will immediately return with a LOCKED status rather than indefinitely waiting on the COTS user to close their window on that record?
I have a temporary table that I'm using and I have a unique column, example:myID INT UNIQUE
Would this create an index on that column? Or do I have to explicitly create the index?
If i have a table with two fields.customer id and order.
let's say i have in total order ID 1,2,3,4
all the customer can have all the four orders.like below
1234 1
1234 2
1234 3
1234 4
3245 3
3245 4
5436 2
5436 4
you can see above that 3245 customer doesnt have order id 1 and 2.
how could i print in the query output like
3245 1
3245 2
5436 1
5436 3
EDIT: i dont have order table but i have list of order's like we can hard code it in the query(1,2,3,4) i dont have an orders table.
eg:table
pkey --guid
annualpay
datefrom
dateto--if null means current record
percentannualincrease
percent annual increase will be calculated only if there is a difference in newly inserted and previously existing last differing value.
percentannualincrease =
([newannualpay-just previous pay(if different from current)]/newannualpay)*100
eg
newid(),5000,today,null,0--very first row
newid(),5000,today+1,null(*),0
newid,5500,today+2,null(*),?????????????--> need to be calculated before insert
*--insert will close the previous record by updating dateto=null to todays date
How can I do this stuff in a trigger???
So, MongoDB defaults to "AND" when finding records. For example:
db.users.find({age: {'$gte': 30}, {'$lte': 40}});
The above query finds users = 30 AND <= 40 years old.
How would I find users <= 30 OR = 40 years old?
Hi. I need to set datetime variable to two days from now but it's time part must be 18:00.
For example if i call getdate() now i'll get 2010-05-17 13:18:07.260. I need to set it to 2010-05-19 18:00:00.000.
Does anybody have a good snippet for that or any ideas how to do it right?
I have a report that we need to link (which we've checked to be working) to in a JSF project, the link looks like the following:
http://www.example.com/report/summary&rs:Command=Render
However when we try to load the page that links to it we get the following error:
The reference to entity "rs:Command" must end with the ';'
How can I link to the report within my pages and prevent it from trying to parse the rs:Command?
Hello, I have MSSQL 2008 Ent and OLTP database with two big tables. How I can move this tables to another filegroup without service interrupting? Now, about 100-130 records inserted and 30-50 records updated each second in this tables. Each table have about 100M records and six fields (including one field geography).
I looking for solution via google, but all solutions contain "create second table, insert rows from first table, drop first table, bla bla bla".
Can I use partitioning functions for solving this problem? Thank you.
If I want to get a user that has the email address of '[email protected]', how do I pass that as a parameter in linq?
ie.:
var a = from u in Users
where u.Email = @email
Select u;
So this would be used in my method:
public static GetuserByEmail(string email)
Do I just pass in the variable or?
I have a bunch of records I want to move to another database and I just want to create a bunch of inserts that I can copy and paste. I've seen someone do this before but I can't figure it out. I'm not getting the escapes right.
It's something like this where 'Code', 'Description' and 'Absent' are the columns I want from the table.
SELECT 'INSERT INTO AttendanceCodes
(Code, Description, Absent)
VALUES
(' + Code + ',' + Description + ',' + Absent')'
FROM AttendanceCodes
The end result should be a slew of INSERTS with the correct values like this:
INSERT INTO AttendanceCodes
(Code, Description, Absent)
VALUES
('A','Unverified Absence','UA')
I have a table that stores a bunch of diagnosis for a single plan. When the users create a new plan I need to copy over all existing diagnosis's as well. I had thought to try the below but this is obviously not correct. I am guessing that I will need to loop through my oldDiagnosis part, but how?
Thanks!
My Attempt so far...
public static void CopyPlanDiagnosis(int newPlanID, int oldPlanID)
{
using (var context = McpDataContext.Create())
{
var oldDiagnosis =
from planDiagnosi in context.tblPlanDiagnosis
where planDiagnosi.PlanID == oldPlanID
select planDiagnosi;
var newDiagnosis = new tblPlanDiagnosi
{
PlanID = newPlanID,
DiagnosisCueID = oldDiagnosis.DiagnosisCueID,
DiagnosisOther = oldDiagnosis.DiagnosisOther,
AdditionalInfo = oldDiagnosis.AdditionalInfo,
rowguid = Guid.NewGuid()
};
context.tblPlanDiagnosis.InsertOnSubmit(newDiagnosis);
context.SubmitChanges();
}
}
can any one explain hiow this query works..It's for getting the Nth largest elemet from a table.here it's 4 th largest
SELECT a.ID
FROM tblitem a
WHERE (4) = (select count(*)
from tblItem b
where b.id < a.id)
Thanks in advance
I have an web application that creates printable forms, these forms have a unique number on them, the problem is I have 2 forms that separate numbers need to be created for them.
ie)
Form1- Numbered 2000000-2999999
Form2- Numbered 3000000-3999999
dbo.test2 - is my form information table
Tsel - is my autoinc table for the 3000000 series numbers
Tadv - is my autoinc table for the 2000000 series numbers
What I have done is create 2 tables with just autoinc row (one for 2000000 series numbers and one for 3000000 series numbers), I then created a trigger to add a record to the coresponding table, read back the autoinc number and add it to my table that stores the form information including the just created autoinc number for the right series of forms.
Although it does work, I'm concerned that the numbers will get messed up under load.
I'm not sure the @@IDENTITY will always return the right value when many people are using the system. (I cannot have duplicates and I need to use the numbering form show above.
See code below.
** TRIGGER **
CREATE TRIGGER MAKEANID2 ON dbo.test2
AFTER INSERT
AS
SET NOCOUNT ON
declare @someid int
declare @someid2 int
declare @startfrom int
declare @test1 varchar(10)
select @someid=@@IDENTITY
select @test1 = (Select name1 from test2 where sysid = @someid )
if @test1 = 'select'
begin
insert into Tsel Default values
select @someid2 = @@IDENTITY
end
if @test1 = 'adv'
begin
insert into Tadv Default values
select @someid2 = @@IDENTITY
end
update test2
set name2=(@someid2) where sysid = @someid
SET NOCOUNT OFF
SELECT EmployeeMaster.EmpNo, Sum(LeaveApplications.LeaveDaysTaken) AS LeaveDays
FROM EmployeeMaster FULL OUTER JOIN
LeaveApplications ON EmployeeMaster.id = LeaveApplications.EmployeeRecordID INNER JOIN
LeaveMaster ON EmployeeMaster.id = LeaveMaster.EmpRecordID
GRoup BY EmployeeMaster.EmpNo
order by LeaveDays Desc
with the above query, if an employee has no leave application record in table LeaveApplications, then their Sum(LeaveApplications.LeaveDaysTaken) AS LeaveDays column returns NULL. What i would like to do is place a value of 0 (Zero) instead of NULL. I want to do this because i have a calculated column in the same query whose formular depends on the LeaveDays returned and when LeaveDays is NULL, the formular some how fails. Is there away i can put 0 for NULL such that that i can get my desired result.
I have a table that has millions of records and we are looking at implementing table partitioning. Looking at it we have a foreign key "GroupID" that we would like to partition on. Is this possible?
The Group will have more entries added to it, so as new GroupID's are added can the partition's be made dynamically?