I have a database that has a 28gig transaction log file. Recovery mode is simple. I just took a full backup of the database, and then ran both:
backup log dbmcms with truncate_only
DBCC SHRINKFILE ('Wxlog0', TRUNCATEONLY)
The name of the db is db_mcms and the name of the transaction log file is Wxlog0.
Neither has helped. I'm not sure what to do next.
Hi all,
I have a table from which i need to get the count grouped on two columns.
the table has two columns one datetime column and another one is success value(-1,1,0)
What i am looking for is something like this...
count of success value for each month
month----success-----count
11------- -1 ------- 50
11------- 1 --------- 50
11------- 0 ------- 50
12------- -1 ------- 50
12------- 1 ------- 50
12------- 0 ------- 50
if there is no success value for a month then the count should be null or zero.
I have tried with left outer join as well but of no use it gives the count incorrectly.
Thanks in advance
Sasi
I have a Product table with the fields Id, Title, Description, Keywords (just comma separated list of keywords).
Table is full-text indexed.
When I view one product, I do a query and search the full-text catalog for any related products based on the Keywords field.
select * from Products where Contains(Products.*, @keywordsFromOneProduct)
Works like a charm.
Now I would like to list all products and all their related products in a big list and I want to avoid calling this method for each item.
Any ideas how could I do it? I was thinking about a job that would go through products one by one and build a one-many mapping table (fields ProductId, RelatedProductId), but I wonder is there a better way?
Hi,
I have two tables:
create table [dbo].[Main]
(
[ID] [int] identity(1,1) primary key not null,
[Sign] [char](1) not null
)
create table [dbo].[Names]
(
[ID_Main][int] primary key not null,
[Name][nvarchar](128) not null,
constraint [FK_Main_Users] foreign key ([ID_Main]) references [dbo].[Main]([ID]),
constraint [CK_Name] unique ([Name], [Sign])
)
The problem is with the second constraint CK_Name
Is there a way to make a constraint target column from a foreign table?
i have a combobox on a form
i want the text of the combobox to be passed into a query.
my query is:
select..from..where something=[Forms]![Enter Data]![comboCup]
the form name is enter data and the combobox name is combocup. should i do:
[Forms]![Enter Data]![comboCup]![text]
or
[Forms]![Enter Data]![comboCup]![value]
??
I am creating a table ,in the table two column is unique, I mean columnA and columnB do not have same value:
such as :
Table X
A B
1 2(RIGHT,unique)
2 2(RIGHT, unique)
1 3(RIGHT, not unique)
2 3(RIGHT, not unique)
1 2 (WRONG, not unique)
How to create such a table?
many thanks!
I have a table whose columns are varchar(50) and a float - I need to (very quickly) look get the float associated with a given string. Even with indexing, this is rather slow. I know, however, that each string is associated with an integer, which I know at the time of lookup, so that each string maps to a unique integer, but each integer does not map to a unique string. One might think of it as a tree structure. Is there anything to be gained by adding this integer to the table, indexing on it, and using a query like
SELECT floatval FROM mytable WHERE phrase=givenstring AND assoc=givenint?
This is Postgres, and if you couldn't tell, I have very little experience with databases.
I'm building a Javascript application and eash user has an individual UserSession. The application makes a bunch of Ajax calls. Each Ajax call needs access to a single UserSession object for the user.
Each Ajax call needs a UserSession object.
Data in the UserSession object is unique to each user.
Originally, during each Ajax call I would create a new UserSession object and it's data members were stored in the ASP.NET Session. However, I found that the UserSession object was being instantiated a lot. To minimize the construction of the UserSession object, I wrapped it in a Singleton pattern and sychronized access to it.
I believe that the synchronization is happening application wide, however I only need it to happen per user. I saw a post here that says the ASP.NET cache is synchronized, however the time between creating the object and inserting it into the cache another Thread could start construction it's another object and insert it into the cache.
Here is the way I'm currently synchronizing access to the object. Is there a better way than using "lock"... should be be locking on the HttpContext.Session object?
private static object SessionLock = new object();
public static WebSession GetSession
{
get
{
lock (SessionLock)
{
try
{
var context = HttpContext.Current;
WebSession result = null;
if (context.Session["MySession"] == null)
{
result = new WebSession(context);
context.Session["MySession"] = result;
}
else
{
result = (WebSession)context.Session["MySession"];
}
return result;
}
catch (Exception ex)
{
ex.Handle();
return null;
}
}
}
}
I'm looking for the best way to display all rows from two tables while joining first by one field (dwg) then where applicable a 2nd join on part.
Table1 data consists of schematics(dwg) along with a list of parts required to build the item depicted in the drawing. Table2 consists of data about the actual parts ordered to build the schematic. Some parts in table2 are a combination of parts in table1 (ex: foo and bar in table1 were ordered as foobar in table2).
I can display all rows in both tables with UNION ALL, but this doesn't join on both the dwg and part fields. I looked at FULL OUTER JOIN also, but I haven't figured out how to join first by dwg, then by part. Here is an example of the data.
table1 table2
dwg part qty order dwg part qty
----- ----- ----- ----- ----- ----- -----
123 foo 1 ord1 123 foobar 1
123 bar 1 ord1 123 bracket 2
123 widget 2 ord2 123 screw 4
123 bracket 4 ord2 123 nut 4
456 foo 1 ord2 123 widget 2
ord2 123 bracket 2
ord3 456 foo 1
Desired output:
The goal is to create a view that provides visibility to all parts in table1 and the associated orders in table2 (including those parts that appear in one but not the other table) so that I can see all the drawing parts in table1 and the associated records in table2 along with records in table2 where the part wasn't in table1.
part_request_order_report
dwg part qty order part qty
----- ----- ----- ------ ----- -----
123 foo 1
123 bar 1
123 widget 2 ord2 widget 2
123 bracket 4 ord1 bracket 2
123 bracket 4 ord2 bracket 2
123 ord1 foobar 1
123 ord1 screw 4
123 ord1 nut 4
456 foo 1 ord3 foo 1
Is this possible? Or am I better off iterating through the data to build the report table? Thanks in advance.
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();
}
}
hey all. I have a table in my DB that has about a thousand records in it. I would like to reset the identity column so that all of the ID's are sequential again. I was looking at this but I'm ASSuming that it only works on an empty table
Current Table
ID | Name
1 Joe
2 Phil
5 Jan
88 Rob
Desired Table
ID | Name
1 Joe
2 Phil
3 Jan
4 Rob
Thanks in advance
Suppose I have a query that returns result like this:
Project Year Type Amt
PJ00001 2012 1 1000
PJ00001 2012 2 1000
PJ00001 2011 1 1000
PJ00002 2012 1 1000
What I want: Every Project will have 2 rows of Types for each Year. If the row is not there, add it to the result with Amt = 0.
For example:
- PJ00001 have 2 rows of type 1,2 in 2012 -- OK. But in 2011, it only have 1 row of Type 1 -- We add one row:PJ00001 2011 2 0
- PJ00002 have only 1 row of type 1 -- add:PJ00002 2012 2 0
Is there a way to easily do it. The only way I know now is to create a view like: PJ_VIEW. And then:
SELECT *
FROM PJ_VIEW
UNION ALL
SELECT t.PROJECT, t.YEAR_NO, 1 AS TYPE_NO, 0 AS AMT
FROM PJ_VIEW t
WHERE NOT EXISTS (SELECT 1 FROM PJ_VIEW t2 WHERE t2.PROJECT = t.PROJECT AND t2.YEAR_NO = t.YEAR_NO AND t2.TYPE_NO = 1)
UNION ALL
SELECT t.PROJECT, t.YEAR_NO, 2 AS TYPE_NO, 0 AS AMT
FROM PJ_VIEW t
WHERE NOT EXISTS (SELECT 1 FROM PJ_VIEW t2 WHERE t2.PROJECT = t.PROJECT AND t2.YEAR_NO = t.YEAR_NO AND t2.TYPE_NO = 2)
Hello Experts,
I have a flat text file data which I import into MSSQL table.
It creates and table with specified name along with multiple columns as per data file.
now I need a query which will return the data and its count. e.g.
data file :
BREAD,MILK
BREAD,DIAPER,BEER,EGGS
MILK,DIAPER,BEER,COKE
BREAD,MILK,DIAPER,BEER
BREAD,MILK,DIAPER,COKE
BREAD,ICE,MANGO
JUICE,BURGER
Result should be
BREAD | 5
MILK | 4
DIAPER| 4
and so on.
I am developing an application for Windows Mobile 6 using an emulator. When I try to open the database connection to the SDF file it is throwing an exception that it is not able to connect or find the file. My questions are:
Where on the mobile device is the SDF file supposed to be deployed?
Does the SDF file get automatically deployed to the emulator when I build the project (like in then windows forms app) or do I have to do that manually?
Any help would be appreciated.
product table
pid modelnumber
1 a
2 b
3 c
ProductTransation
pid name description...
1 ball ball
2 bat cricket bat
i create fullText for Modelnumber in product table.
" for name & Description in productTrasaction table.
Now i want to join this table if i search through modelnumber or name
result should be
pid name modelnumber
1 ball a
we want to have the second biggest element. We first use ANY to exclude the biggest one. Then we use all to select the biggest. However when we run this query, it shows the biggest and not the second one. Why?
SELECT *
FROM bestelling
WHERE totaalprijs > ALL
(
SELECT totaalprijs
FROM bestelling
WHERE totaalprijs < ANY
(
SELECT totaalprijs
FROM bestelling
)
)
elements in the table:
157.00
5.00
82.80
15.00
20.00
20.00
I have a table of basketball leagues, a table af teams and a table of players like this:
LEAGUES
ID | NAME |
------------------
1 | NBA |
2 | ABA |
TEAMS:
ID | NAME | LEAGUE_ID
------------------------------
20 | BULLS | 1
21 | KNICKS | 2
PLAYERS:
ID | TEAM_ID | FIRST_NAME | LAST_NAME |
---------------------------------------------
1 | 21 | John | Starks |
2 | 21 | Patrick | Ewing |
Given a League ID, I would like to retrieve all the players' names and their team ID from all the teams in that league, so I do this:
SELECT t.id AS team_id, p.id AS player_id, p.first_name, p.last_name
FROM teams AS t
JOIN players AS p ON p.team_id = t.id
WHERE t.league_id = 1
which returns:
[0] => stdClass Object
(
[team_id] => 21
[player_id] => 1
[first_name] => John
[last_name] => Starks
)
[1] => stdClass Object
(
[team_id] => 21
[player_id] => 2
[first_name] => Patrick
[last_name] => Ewing
)
+ around 500 more objects...
Since I will use this result to populate a dropdown menu for each team containing each team's list of players, I would like to group my result by team ID, so the loop to create these dropdowns will only have to cycle through each team ID instead of all 500+ players each time.
But when I use the GROUP BY like this:
SELECT t.id AS team_id, p.id AS player_id, p.first_name, p.last_name
FROM teams AS t
JOIN players AS p ON p.team_id = t.id
WHERE t.league_id = 1
GROUP BY t.id
it only returns one player from each team like this, overriding all the other players on the same team because of the use of the same column names.
[0] => stdClass Object
(
[team_id] => 21
[player_id] => 2
[first_name] => Patrick
[last_name] => Ewing
)
[1] => stdClass Object
(
[team_id] => 22
[player_id] => 31
[first_name] => Shawn
[last_name] => Kemp
)
etc...
I would like to return something like this:
[0] => stdClass Object
(
[team_id] => 2
[player_id1] => 1
[first_name1] => John
[last_name1] => Starks
[player_id2] => 2
[first_name2] => Patrick
[last_name2] => Ewing
+10 more players from this team...
)
+25 more teams...
Is it possible somehow?
It seems like a no brainer to me. I've heard countless stories about people forgetting the WHERE clause in an UPDATE or DELETE and trashing an entire table. I know that careless people shouldn't be issuing queries directly and all that... and that there are legitimate cases where you want to affect all rows, but wouldn't it make sense to have an option on by default that requires such queries to be written like:
UPDATE MyTable SET MyColumn = 0 WHERE *
Or without changing the language,
UPDATE MyTable SET MyColumn = 0 WHERE 1 = 1 -- tacky, I know
This question is about what happens with the reorganizing of data in a clustered index when an insert is done. I assume that it should be more expensive to do inserts on a table which has a clustered index than one that does not because reorganizing the data in a clustered index involves changing the physical layout of the data on the disk. I'm not sure how to phrase my question except through an example I came across at work.
Assume there is a table (Junk) and there are two queries that are done on the table, the first query searches by Name and the second query searches by Name and Something. As I'm working on the database I discovered that the table has been created with two indexes, one to support each query, like so:
--drop table Junk1
CREATE TABLE Junk1
(
Name char(5),
Something char(5),
WhoCares int
)
CREATE CLUSTERED INDEX IX_Name ON Junk1
(
Name
)
CREATE NONCLUSTERED INDEX IX_Name_Something ON Junk1
(
Name, Something
)
Now when I looked at the two indexes, it seems that IX_Name is redundant since IX_Name_Something can be used by any query that desires to search by Name. So I would eliminate IX_Name and make IX_Name_Something the clustered index instead:
--drop table Junk2
CREATE TABLE Junk2
(
Name char(5),
Something char(5),
WhoCares int
)
CREATE CLUSTERED INDEX IX_Name_Something ON Junk2
(
Name, Something
)
Someone suggested that the first indexing scheme should be kept since it would result in more efficient inserts/deletes (assume that there is no need to worry about updates for Name and Something). Would that make sense? I think the second indexing method would be better since it means one less index needs to be maintained.
I would appreciate any insight into this specific example or directing me to more info on maintenance of clustered indexes.
Say I take an arbitrary LINQ2SQL query's Expression, is it possible to invoke it somehow?
MyContext ctx1 = new MyContext("...");
var q = from t in ctx1.table1 where t.id = 1 select t;
Expression qe = q.Expression;
var res = Expression.Invoke(qe);
This throws ArgumentException "Expression of type System.Linq.IQueryable`1[...]' cannot be invoked".
My ultimate goal is to evaluate the same query on several different data contexts.
Originally I had 2 tables in my DB, [Property] and [Employee].
Each employee can have 1 "Home Property" so the employee table has a HomePropertyID FK field to Property.
Later I needed to model the situation where despite having only 1 "Home Property" the employee did work at or cover for multiple properties.
So I created an [Employee2Property] table that has EmployeeID and PropertyID FK fields to model this many 2 many relationship.
Now I find that I need to create other many-to-many relationships between employees and properties. For example if there are multiple employees that are managers for a property or multiple employees that perform maintenance work at a property, etc.
My questions are:
1) Should I create seperate many-to-many tables for each of these situations or should I just create 1 more table like [PropertyAssociatonType] that lists the types of associations an emploee can have with a property and just add a FK field to [Employee2Property] such a PropertyAssociationTypeID that explains what the association is? I'm curious about the pros/cons or if there's another better way.
2) Am I stupid and going about this all worng?
Thanks for any suggestions :)
I havea 70MB db of my website which is hosted with a provider. I am able to access my db using SSMS 2008 remotely.
On a running website, which is the best way I can back up the db locally on machine
Thanks
I'd like to create a table:
CREATE TABLE sfc.OpenId (
Url VARCHAR(255) PRIMARY KEY,
UserGuid uniqueidentifier NOT NULL references dbo.aspnet_users(userId),
)
...with an index on UserGuid.
Is it possible to create that index in the create table statement?