Showing posts with label tables. Show all posts
Showing posts with label tables. Show all posts

Thursday, March 29, 2012

Dreaded TEXT column

I need to setup repliaction between A and B. I have high transaction /min count. Some tables have TEXT columns. This is what i am planning to do:

Example: table name is CREDITS

vertical partition the table into two. First table (will be called CREDITS_PRI) holds PK column and non TEXT columns, second table (will be called CREDITS_SEC) holds PK column and TEXT columns.

Create a view called CREDITS with INSTEAD OF triggers for inserts, updates and deletes. So far so good. Then setup replication with immediate updating subscription between A and B for tables called ..._PRI and merge replication between A and B for tables called ..._SEC.

Would this work? How do other companies handle this? thank you in advance for pointing me into the right direction.

Lars

Yes, this would work, you could also leave your tables intact the way they were and implement bi-directional transactional replication.

However I assume you're on SQL 2000, correct? If you're on SQL 2005, immediate updating would work just fine if you replaced text datatype with varchar(max) datatype, it's also more optimal and efficient in terms of data storage.

|||

Thank you,

yes, we still are on SQL 2000 and won't upgrade until another 6 months. I have never heard of bi-directional replication since it wasn't mentioned anywhere. I found a great link on MS com and will take a look at it. Thanks again.

L

Dramatical performance degradation after removing / adding indexes

Very strange problem occurs when we removed from few tables indexes and added it again. Database after that operation is noticeably slower than the same DB before.
Also the DB after removal / adding indexes seems to be different in a unknown way.
I could prove that running SQL Analyzer - query plan analysis on both DBs are different before operation and after that!!! (?)
So the DBs are identical but in some strange way different.
Could you have any ideas or maybe it is known SQL Srv 2000 problem?
We run SQL 2000 SP3.
Kind regards,
Adam Heczko
Just recompile your stored procedures and views - generate script for
drop/create and run it.
Bojidar Alexandrov
|||Adam
Try to update statistics
"Adam Heczko" <a.heczko@.zibico.com.pl> wrote in message
news:933E6C88-A99E-40BB-A080-B0C8FBB722C7@.microsoft.com...
> Very strange problem occurs when we removed from few tables indexes and
added it again. Database after that operation is noticeably slower than the
same DB before.
> Also the DB after removal / adding indexes seems to be different in a
unknown way.
> I could prove that running SQL Analyzer - query plan analysis on both DBs
are different before operation and after that!!! (?)
> So the DBs are identical but in some strange way different.
> Could you have any ideas or maybe it is known SQL Srv 2000 problem?
> We run SQL 2000 SP3.
> Kind regards,
> Adam Heczko
|||are you sure you rebuilt the indexes in the same way they were built before
?
Fill Factor Settings
Pad_Index Settings
File Group, etc etc etc
?
Greg Jackson
PDX, Oregon
|||> are you sure you rebuilt the indexes in the same way they were built before
> ?
> Fill Factor Settings
> Pad_Index Settings
> File Group, etc etc etc
>
> ?
> Greg Jackson
> PDX, Oregon
>
Yes, we tried to rebuild stored procedures, views etc. - nothing really
helped.
Adam Heczko

Dramatical performance degradation after removing / adding indexes

Very strange problem occurs when we removed from few tables indexes and adde
d it again. Database after that operation is noticeably slower than the same
DB before.
Also the DB after removal / adding indexes seems to be different in a unknow
n way.
I could prove that running SQL Analyzer - query plan analysis on both DBs ar
e different before operation and after that!!! (?)
So the DBs are identical but in some strange way different.
Could you have any ideas or maybe it is known SQL Srv 2000 problem?
We run SQL 2000 SP3.
Kind regards,
Adam HeczkoJust recompile your stored procedures and views - generate script for
drop/create and run it.
Bojidar Alexandrov|||Adam
Try to update statistics
"Adam Heczko" <a.heczko@.zibico.com.pl> wrote in message
news:933E6C88-A99E-40BB-A080-B0C8FBB722C7@.microsoft.com...
> Very strange problem occurs when we removed from few tables indexes and
added it again. Database after that operation is noticeably slower than the
same DB before.
> Also the DB after removal / adding indexes seems to be different in a
unknown way.
> I could prove that running SQL Analyzer - query plan analysis on both DBs
are different before operation and after that!!! (?)
> So the DBs are identical but in some strange way different.
> Could you have any ideas or maybe it is known SQL Srv 2000 problem?
> We run SQL 2000 SP3.
> Kind regards,
> Adam Heczko|||are you sure you rebuilt the indexes in the same way they were built before
?
Fill Factor Settings
Pad_Index Settings
File Group, etc etc etc
?
Greg Jackson
PDX, Oregon|||> are you sure you rebuilt the indexes in the same way they were built before">
> ?
> Fill Factor Settings
> Pad_Index Settings
> File Group, etc etc etc
>
> ?
> Greg Jackson
> PDX, Oregon
>
Yes, we tried to rebuild stored procedures, views etc. - nothing really
helped.
Adam Heczkosql

Dramatical performance degradation after removing / adding indexes

Very strange problem occurs when we removed from few tables indexes and added it again. Database after that operation is noticeably slower than the same DB before
Also the DB after removal / adding indexes seems to be different in a unknown way
I could prove that running SQL Analyzer - query plan analysis on both DBs are different before operation and after that!!! (?
So the DBs are identical but in some strange way different
Could you have any ideas or maybe it is known SQL Srv 2000 problem
We run SQL 2000 SP3
Kind regards
Adam HeczkoJust recompile your stored procedures and views - generate script for
drop/create and run it.
Bojidar Alexandrov|||Adam
Try to update statistics
"Adam Heczko" <a.heczko@.zibico.com.pl> wrote in message
news:933E6C88-A99E-40BB-A080-B0C8FBB722C7@.microsoft.com...
> Very strange problem occurs when we removed from few tables indexes and
added it again. Database after that operation is noticeably slower than the
same DB before.
> Also the DB after removal / adding indexes seems to be different in a
unknown way.
> I could prove that running SQL Analyzer - query plan analysis on both DBs
are different before operation and after that!!! (?)
> So the DBs are identical but in some strange way different.
> Could you have any ideas or maybe it is known SQL Srv 2000 problem?
> We run SQL 2000 SP3.
> Kind regards,
> Adam Heczko|||are you sure you rebuilt the indexes in the same way they were built before
?
Fill Factor Settings
Pad_Index Settings
File Group, etc etc etc
?
Greg Jackson
PDX, Oregon|||> are you sure you rebuilt the indexes in the same way they were built before
> ?
> Fill Factor Settings
> Pad_Index Settings
> File Group, etc etc etc
>
> ?
> Greg Jackson
> PDX, Oregon
>
Yes, we tried to rebuild stored procedures, views etc. - nothing really
helped.
Adam Heczko

Thursday, March 22, 2012

Download database to local and use

I have SQL database hosted by my ISP. Every now and again we log on and create new tables using user XXX1. After getting a backup of the database, I have restored it on my local machine. When running the application on local, I get an error because there is a new user in database called XXX1.

I would like to change the user from XXX1 to dbo on my local machine for all tables, stored procedures and views. How do I do this easily?

Thanks in advance!

Dave

Hi,

http://groups.google.de/group/microsoft.public.sqlserver.programming/browse_frm/thread/f1625d70fb765701

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

Wednesday, March 21, 2012

Down Sizing from SQL server to MSDE?

Hi everyone,
Does anyone know if I can take tables from SQL server and somehow get them
into MSDE. I'm using Access as a front end to both servers. I know there is
a way to upsize databases, as well there should be, but what are my options
in terms of downsizing?
Thanks everyone
Take Care
SimonScripting the tables and then using INSERT INTO should work fine.
--
--
Allan Mitchell (Microsoft SQL Server MVP)
MCSE,MCDBA
www.SQLDTS.com
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org
"Simon Harvey" <sh856531@.microsofts_free_emal_service.com> wrote in message
news:SerXa.52566$9C6.3100247@.wards.force9.net...
> Hi everyone,
> Does anyone know if I can take tables from SQL server and somehow get them
> into MSDE. I'm using Access as a front end to both servers. I know there
is
> a way to upsize databases, as well there should be, but what are my
options
> in terms of downsizing?
> Thanks everyone
> Take Care
> Simon
>|||I think I'd try sp_detachdb and sp_attachdb and see if that works ( it
should I think.)
--
Wayne Snyder, MCDBA, SQL Server MVP
Computer Education Services Corporation (CESC), Charlotte, NC
www.computeredservices.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it community
of SQL Server professionals.
www.sqlpass.org
"Simon Harvey" <sh856531@.microsofts_free_emal_service.com> wrote in message
news:SerXa.52566$9C6.3100247@.wards.force9.net...
> Hi everyone,
> Does anyone know if I can take tables from SQL server and somehow get them
> into MSDE. I'm using Access as a front end to both servers. I know there
is
> a way to upsize databases, as well there should be, but what are my
options
> in terms of downsizing?
> Thanks everyone
> Take Care
> Simon
>

Monday, March 19, 2012

Down and dirty database infrastructure

Does any have a link, or know of an MS book(s) that details the
underlying database structure, tables, processes? Something that
explains in detail how/why this stuff is configured and works, like
DDL, TDS, varchar, int, index, tables, normalization, DML, Primary
Key/Foreign key.Beeker (sqlserver2005dba@.gmail.com) writes:
> Does any have a link, or know of an MS book(s) that details the
> underlying database structure, tables, processes? Something that
> explains in detail how/why this stuff is configured and works, like
> DDL, TDS, varchar, int, index, tables, normalization, DML, Primary
> Key/Foreign key.

Sounds like you are looking for "Inside SQL Server 2000" by Kalen
Delaney.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Thanks much.

The review, on Barnes and Nobel (
http://search.barnesandnoble.com/bo...isbn=0735609985
), on her treatment of internals and other vaulable info are very
critical.

Then the Amazon comments praise her.
(
http://www.amazon.com/gp/product/07...406348?n=283155
).

Comment?|||"Beeker" <sqlserver2005dba@.gmail.com> wrote in message
news:1143721430.783394.148200@.t31g2000cwb.googlegr oups.com...
> Thanks much.
> The review, on Barnes and Nobel (
http://search.barnesandnoble.com/bo...isbn=0735609985
> ), on her treatment of internals and other vaulable info are very
> critical.
> Then the Amazon comments praise her.
> (
http://www.amazon.com/gp/product/07...406348?n=283155
> ).
> Comment?

She knows her stuff. Extremely knowledgeable. Get the book.

You want a book on XML, there are definitely better ones.|||Thanks Strider.

Doubt

Hi there

I have a question here. I need to import the excel template into sql server data base tables. I did worked on the regular importing of excel spread sheets to import into the appropriate data base columns. I am not getting idea with the eacel template. My main goal is to import the excel template to sql tables and then reproduce the same template for the user in the browser. If any body can help i would really appreciate....Welcome to the forums..looks like you signed up just a few mins back.

can you xplain your q in a more detailed way.
>>I am not getting idea with the eacel template.
Did you mean you are not able to use the DTS Wizard to import the excel file into a sql table ?

>> My main goal is to import the excel template to sql tables and then reproduce the same template for the user in the browser.

I didnt understand this part either.|||Yes I can't use the regular DTS ti import into the data Base tables. Because the the excel templates might be in any order and they have data in any way. I have a sample application with title, genere, format size , frequency, attributes and insertion costs as columns in excel template. The data can come or can't come in exact order as in regular excel spread sheets. I have to read the data cell by cell and import into the data base. For that I can't use the Microsoft Jet provider . I can use the Jet for the regular spread sheets, but not for the templates. The template where I import the data into the data base, I need to make a look up for each and every tables.(ex: Market--country--> string look up int fk to the country table, Devision: string look up fk to a devision table) and at the end I need to display the information to the end user according to his needs. So please tell me any ideas how I can make a look up and how I can read the data from excel template and finally import into sql tables.|||you can prbly write a stored proc that will query from a table . you can import your excel sheet into an sql table. use that as a container..then write a select stmt to query against that table. assuming the column names will be the same no matter what order they are in, this approach might work. IF the column names are also different then it will require a human to read through to identify the columns.|||Do you have any idea about the look ups. How to design the data base for that excel template. Here is I got some sentences...

User uploads an excel sheet template that has been filled out.

Header:

Market -- country string lookup int fk to a country table
Business Group -- division string lookup fk to division table
ALLOCATED BUDGET: float
GRPs (IF APPLICABLE): float
% REACH (IF APPLICABLE): float
OTS (IF APPLICABLE): float
start date smalldatetime
end date smalldatetime
flight type char[1]

row data:

Title string lookup int fk to a media location table
Frequency -- you can ignore insert as it is driven by title
Client cost float
Insertion cost float
Genre string lookup fk to Genre table
Start date smalldatetime
end date smalldatetime
Booking Date smalldatetime
Material Date smalldatetime
Onsale Date smalldatetime
Attrb 1 -- 10 varchars any number of attributes from 0 through 10 posibblities based on flight type (ie circulation format/size) which are
fk to title table

Iam not understanding the what the header is and what the row data is...How sould I make the look ups...Thanks for you answers.|||(1) Market -- country string lookup int fk to a country table
can you xplain what this means.

(2) are you trying to this thing programmatically or manually.|||Iam also understanding that much. If you can explain me what's the look up and how to make a look up in the data base?. What kind of queries you write to get the thing I want that would be great.....

Market -- country string lookup int fk to a country table

I feel if suppose the country is India and country ID is 15, whenever I should enter 15 I need to get India. i think this is the look up...If you knowsome thing about how to make look ups please explain me....

Sunday, March 11, 2012

Double Table Insert

Tables :

EmailUsers
ID int - PK
Email nvarchar(256)

ListsUsers
ListID int - FK to List Table - Combo PK
UserID int - FK to EmailUsers Table - Combo PK

When a person adds a user I need to:
A. insert them as a new entry into EmailUsers - no problem
B. insert their EmailUsers.ID from step A and ListID (passed in parameter) into ListsUsers - not so easy
C. if they're already in EmailUsers don't insert them but pass their existing EmailUsers.ID to part B

Any thoughts or examples I can follow? Maybe it's easier to do two seperate queries and control the if exists logic in asp.net?I would check out the starter kits--such as the TimeTracker. They illustrate the following:

if select Count(*) from emailusers where .. = 0
Begin
Begin Transaction

insert into Email users

select @.id = @.@.identity

if no error
continue

insert into ListUsers
(x, @.id)

Commit Trans
end
else
select @.id = id from emailusers

insert into ListUsers
(x, @.id)

Hope this points you in the right direction|||


CREATE PROCEDURE SaveUser
@.EmailAddress VARCHAR(256),
@.ListID INT
AS
DECLARE @.UserID INT

SELECT @.UserID = ID FROM EmailUsers WHERE Email = @.EmailAddress

IF @.UserID IS NULL
BEGIN
INSERT INTO EmailUsers (Email) VALUES (@.EmailAddress)
SET @.UserID = @.@.IDENTITY
END

INSERT INTO ListUsers (ListID, UserID) VALUES (@.ListID, @.UserID)

|||I'd say use SCOPE_IDENTITY() rather than @.@.IDENTITY.. if there was another insert at the same time @.@.IDENTITY will return the id of that insert. SCOPE_IDENTITY() will work within the scope of the insert..

hth|||ndinakar: Thanks for that little tidbit, I didn't realize there was a potential for scope issues with @.@.IDENTITY.|||it should be ok to use @.@.IDENTITY as there could be 1/1000 ( or more or less...just a guesstimate) chance of your insert coinciding with another one but that could very well runi your day...so...check out BOL for more info on them...

hth|||I was in Vegas for the past week. Will give the suggestions here a try on Monday morning.

Thanks!|||Works great but I'm slightly confused on my return value


CREATE PROCEDURE [dbo].[Add_List_Users]
@.EmailAddress nvarchar(256),
@.ListID INT
AS
DECLARE @.UserID INT
DECLARE @.returnCode INT
SELECT @.UserID = ID FROM Email_Users WHERE Email = @.EmailAddress
SET @.returnCode = 0
IF @.UserID IS NULL
BEGIN
INSERT INTO Email_Users (Email) VALUES (@.EmailAddress)
SET @.UserID = @.@.IDENTITY
SET @.returnCode = @.returnCode + 1
END
if not exists (select * from Lists_Users where ListID = @.ListID and UserID = @.UserID)
INSERT INTO Lists_Users (ListID, UserID) VALUES (@.ListID, @.UserID)
SET @.returnCode = @.returnCode + 2
return @.returnCode
GO

Scenarios:
User Added to Users Table and List Table - returnCode 3
User exists in Users Table and Added to List Table - return code 2
User exists in both tables - return code 0

Actual Return Values:
2
1
-1

That's fine, I just check for 2, 1, -1 instead of 3, 2, 0 but I'd like to know why the values returned aren't logically what they should be?

SET @.returnCode = 0
SET @.returnCode = @.returnCode + 1
SET @.returnCode = @.returnCode + 2
shouldn't that = 3??

It's as if @.returnCode starts off at -1 since all the return values are 1 less than I expect them to be.|||The SCOPE_IDENTITY really comes into play if you've got hidden inserts. For example, another insert triggered from your original insert. That's where simply returning @.@.IDENTIY becomes totally wrong. Like the poster said, use SCOPE_IDENTITY and you can sleep at night!|||plus..you might want to look at OUTPUT Parameters to return the id ..check out BOL for more info on OUTPUT parameters..

hth

Double left joins with conditions

I have a setup in an Access database with linked tables to Oracle (its a remote application database that is synced when a connection is available). I have to perform inserts, updates, and deletes based upon records that have changed since the last update. In the examples of inserting records into oracle, I find records in access that do not exist in oracle and meet the date condition. Where I run into problems are in tables like [events]: I need to only be updating, inserting, and deleting events for a specific county but the only place county is designated is in the location table that events are tied to through lctn_id. I just can't figure out how to involve the location table join with the events table join and the necessary conditions.

locations (and locations_ora)
lctn_id, cnty_nbr, lctn_nm..., rec_dt

events (and events_ora)
evnt_id, lctn_id, evnt_txt, ..., rec_dt

Example of format used for another table:
INSERT INTO locations_ora SELECT DISTINCTROW a.* FROM locations a LEFT JOIN locations o ON a.lctn_id=o.lctn_id WHERE (o.lctn_id IS NULL) AND a.rec_dt>#8/17/2000 1:11:11 AM# AND a.cnty_nbr=5

How I would like to get events working:
INSERT INTO events_ora SELECT DISTINCTROW a.* FROM events AS a LEFT JOIN events_ora AS o ON a.evnt_id=o.evnt_id WHERE (o.evnt_id IS NULL) AND a.rec_dt>#8/17/2000 1:11:11 AM# AND {some way to only get events tied locations in a specific county}
-- or even --
INSERT INTO events_ora SELECT DISTINCTROW a.* FROM (SELECT a.* FROM events a LEFT JOIN locations l ON b.lctn_id=l.lctn_id WHERE l.cnty_nbr=5 ) LEFT JOIN events_ora o ON a.evnt_id=o.evnt_id WHERE (o.evnt_id IS NULL) AND a.rec_dt>#1/17/1979 1:11:11 AM#
(I thought this one would work but Access blows up on the SELECT after the FROM.)

Can anyone point me in the right direction?INSERT
INTO events_ora
SELECT a.*
FROM (
events a
inner
JOIN locations l
ON (
l.lctn_id = a.lctn_id
and l.cnty_nbr = 5
)
)
LEFT
JOIN events_ora o
ON o.evnt_id = a.evnt_id
WHERE a.rec_dt>#1/17/1979|||The traffic signals of North Carolina thank you immensely!

Seeing how this is done correctly and in the reading I've done on your site (since I figured you would be the likely responder to my thread) has definitely increased my understanding of how to work with SQL. You will now be added to the Whiteboard of Fame in conference room C-011.|||thanks :)

that's the nicest kudos i've received in a while

Double Inner Join

I have a table where 2 field in a table which are linked to 2 other different tables.

I need to retrieve values from the 3 tables.
Can I use twice the inner join ? like :

select f_tb2,f_tb3,* from tb1
inner join tb2 on tb2.f_id=tb1.an_id and
inner join tb3 on tb3.f_id=tb1.another_id
etc...

Or something like that ?

Or any other method ?

Thanks for help.Originally posted by Plarde
I have a table where 2 field in a table which are linked to 2 other different tables.

I need to retrieve values from the 3 tables.
Can I use twice the inner join ? like :

select f_tb2,f_tb3,* from tb1
inner join tb2 on tb2.f_id=tb1.an_id and
inner join tb3 on tb3.f_id=tb1.another_id
etc...

Or something like that ?

Or any other method ?

Thanks for help.

Yes you can join many columns in a column to any number of tables. Frequently there will be more than one column in a table which needs to correspond to other tables.

When you start talking about outer joining a table to more than one table is when you may run into limitations, but in this case you will definitely be able to do that :)|||yes you can do it, with one correction and one suggestion:

select f_tb2, f_tb3, tb1.*
from tb1
inner join tb2 on tb2.f_id=tb1.an_id and
inner join tb3 on tb3.f_id=tb1.another_id

correction: remove the word "and" from between the joins

suggestion: qualify the asterisk, otherwise it returns all columns from all tables|||here is a rather large query we use regularly with multiple joins:

select item.item,
Item.description,
LocInv.Item_Desc as LIDesc,
WOH.Item_Desc as WOHDesc,
WOD.Item_desc as WODDesc,
WI.Item_desc as WIDesc,
BOMD.Item_desc as BOMDDesc,
BOMH.Item_desc as BOMHDesc
from Item with (nolock)
inner join Location_inventory LocInv with (nolock)
on Item.Item = LocInv.Item
inner join Work_Order_Header WOH with (nolock)
on Item.Item = WOH.Item
inner join Work_Order_Detail WOD with (nolock)
on Item.Item = WOD.Item
inner join Work_Instruction WI with (nolock)
on Item.Item = WI.Item
inner join Bill_Of_Materials_Detail BOMD with (nolock)
on Item.Item = BOMD.Item
inner join Bill_Of_Materials_Header BOMH with (nolock)
on Item.Item = BOMH.Item
where (Item.Description <> LocInv.Item_Desc and Item.Item = LocInv.Item)
or (Item.Description <> WOH.Item_Desc and Item.Item = WOH.Item)
or (Item.Description <> WOD.Item_Desc and Item.Item = WOD.Item)
or (Item.Description <> WI.Item_Desc and Item.Item = WI.Item)
or (Item.Description <> BOMD.Item_Desc and Item.Item = BOMD.Item)
or (Item.Description <> BOMH.Item_Desc and Item.Item = BOMH.Item)

Friday, March 9, 2012

Dont want every row i second table

Hi!

I've got 2 tables that are related

Tabel 1
CatID
CatName

Table2
SubID
CatID
SubName
(So this table can have more than one related CatID, but I would like to only retreive 1 row)

I've tried the diffrent Joins to get what I want, what I like is for the second table to show only one of more rows that are related to first table.

SQL SYNTAX

SELECT DISTINCT
dbo.Tb_DataPaNummer.CID, dbo.Tb_DataPaNummer.OrtID, dbo.Tb_DataPaNummer.PaNummer, dbo.Tb_DataPaNummer.GoodToKnowCom,
dbo.Tb_DataPaNummer.Station, dbo.Tb_DataPaNummer.Laptop, dbo.Tb_DataUser.UserID, dbo.Tb_DataUser.UserName
FROM dbo.Tb_DataPaNummer LEFT OUTER JOIN
dbo.Tb_DataUser ON dbo.Tb_DataPaNummer.CID = dbo.Tb_DataUser.CID
WHERE (dbo.Tb_DataPaNummer.OrtID = 2)

Please help

SELECT

e.CatID, d.CatName, e.SubID, e.SubNameFROM(SELECT a.CatID, a.CatName, c.MaxSubIDFROM CatTable1 aINNERJOIN(SELECT b.CatID,MAX(b.SubID)as MaxSubIDFROM CatSubTable1 b

GROUP

BY b.CatID) cON a.CatID= c.CatID) dINNERJOIN CatSubTable1 eON d.MaxSubID=e.SubID|||Thank you so much!!!!

Wednesday, March 7, 2012

Don't Know How To Explain It

The tables are as follows
CREATE TABLE dbo.Blogs
dId int * PRIMARY
posted datetime(8)
title nvarchar(50)
catgy nvarchar(50)
blogs nvarchar(500)
picId int
UName nvarchar(50)
CREATE TABLE dbo.BlogPix
bgId int * PRIMARY
picId int
Photo nvarchar(50)
Caption(50)
UName nvarchar(50)
I dont know how to explain it but this is the way i have the application
working. The UName on every table in the system is the User name of the User
and it returns rows filtered by UName = @.Uname. However this works fin on my
application but it gets tricky when i try to filter by picId. Ok, the picId
is not a autonumber and any user can get the same number at some time
because i am using the random class to generate a number from the smallest
INT32 to the biggest so i have big scope.
its so hard to explain what i mean so i will give an example,
SELECT TOP (30) *
FROM Blogs INNER JOIN
BlogPix ON Blogs.picId = BlogPix.picId
WHERE UName = @.UName AND PicId = @.PicId
basically i want to retrieve data by using the keyfields dId or picId which
ever way i can so i can return results like the following;
bgId !!!!!!! picId !!!!!!! Photo !!!!!!! Caption !!!!!!! UName
--1--99995688--~/pix/plig.jpg--im a minger--Sean--
--2--99995688--~/pix/pliglet.jpg--im a minger--Sean--
--3--99995688--~/pix/pligkil.jpg--im a minger--Sean--
--4--99995688--~/pix/plipim.jpg--im a minger--Sean--
--5--99995688--~/pix/plim.jpg--im a minger--Sean--
dId !!!!!!! picId !!!!!!! Title !!!!!!!!!!!!!!!!!! Blogs
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Posted
!!!!!!!!!!! Catgy !!!!!!! UName
--1--99995688--Me On A Gud Day--Im going gud and life is great--21
Aug 2005--Music--Sean--
--2--2568777--Me On A Bad Day--Im going gud and life is great--21
Aug 2005--Music--Sean--
--3--12369875--Me On A Nasty Day--Im going gud and life is
great--21 Aug 2005--Music--Sean--
--4--56888999--Me On A Lovely Day--Im going gud and life is
great--21 Aug 2005--Music--Sean--
--5--5896633--Me On A Dark Day--Im going gud and life is great--21
Aug 2005--Music--Sean--
Hope this helps, i cant really explain what it is but i do knowI think you'll find your answers in the following article:
http://www.sommarskog.se/dyn-search.html
Adam Machanic
SQL Server MVP
http://www.datamanipulation.net
--
"Eamon Straughn" <blackmanvandam@.aol.com> wrote in message
news:uUu9KJCrFHA.2076@.TK2MSFTNGP14.phx.gbl...
> The tables are as follows
> CREATE TABLE dbo.Blogs
> dId int * PRIMARY
> posted datetime(8)
> title nvarchar(50)
> catgy nvarchar(50)
> blogs nvarchar(500)
> picId int
> UName nvarchar(50)
> CREATE TABLE dbo.BlogPix
> bgId int * PRIMARY
> picId int
> Photo nvarchar(50)
> Caption(50)
> UName nvarchar(50)
> I dont know how to explain it but this is the way i have the application
> working. The UName on every table in the system is the User name of the
User
> and it returns rows filtered by UName = @.Uname. However this works fin on
my
> application but it gets tricky when i try to filter by picId. Ok, the
picId
> is not a autonumber and any user can get the same number at some time
> because i am using the random class to generate a number from the smallest
> INT32 to the biggest so i have big scope.
> its so hard to explain what i mean so i will give an example,
> SELECT TOP (30) *
> FROM Blogs INNER JOIN
> BlogPix ON Blogs.picId = BlogPix.picId
> WHERE UName = @.UName AND PicId = @.PicId
> basically i want to retrieve data by using the keyfields dId or picId
which
> ever way i can so i can return results like the following;
> bgId !!!!!!! picId !!!!!!! Photo !!!!!!! Caption !!!!!!! UName
> --1--99995688--~/pix/plig.jpg--im a minger--Sean--
> --2--99995688--~/pix/pliglet.jpg--im a minger--Sean--
> --3--99995688--~/pix/pligkil.jpg--im a minger--Sean--
> --4--99995688--~/pix/plipim.jpg--im a minger--Sean--
> --5--99995688--~/pix/plim.jpg--im a minger--Sean--
> dId !!!!!!! picId !!!!!!! Title !!!!!!!!!!!!!!!!!! Blogs
> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Posted
!!!!!!!!!!! Catgy !!!!!!! UName
> --1--99995688--Me On A Gud Day--Im going gud and life is
great--21
> Aug 2005--Music--Sean--
> --2--2568777--Me On A Bad Day--Im going gud and life is great--21
> Aug 2005--Music--Sean--
> --3--12369875--Me On A Nasty Day--Im going gud and life is
> great--21 Aug 2005--Music--Sean--
> --4--56888999--Me On A Lovely Day--Im going gud and life is
> great--21 Aug 2005--Music--Sean--
> --5--5896633--Me On A Dark Day--Im going gud and life is
great--21
> Aug 2005--Music--Sean--
> Hope this helps, i cant really explain what it is but i do know
>

Sunday, February 26, 2012

don't allow duplicates problem

I have MSDE with the server tools from sql server 2000 enterprise edition. I
am having a problem with one of my tables. The table is set up with two
fields Class and Student. I want there to be only one student of the same
name in each class. If i use the primary key it will just allow only one
student of the same name in the entire table and wouldn't look at the class
that the student is taking. Is there an easy way around this?
I found a solution, I created a dual primary key. I highlighted both items
and then turned on the primary key and it does exactly what I wanted it to
except the maximum size is 900bytes for a primary key so I had to adjust the
length of the fields a bit.
"Benjamin" wrote:

> I have MSDE with the server tools from sql server 2000 enterprise edition. I
> am having a problem with one of my tables. The table is set up with two
> fields Class and Student. I want there to be only one student of the same
> name in each class. If i use the primary key it will just allow only one
> student of the same name in the entire table and wouldn't look at the class
> that the student is taking. Is there an easy way around this?

Donno how to work on MSDE?

Hi,

I downloaded and installed MSDE successfully on my comp, but since i have this practice of creating my data base, tables.. using the enterprise manager, i donno how exactly to do the same in. MSDE.

I am new to MSDE, so plz someone explain me to create the database and the tables in MSDE.

and another question is that.. i have created 2 instances of the same.. but donno what these instances exactly are ?

can anyone plz explain me all these..?

Try downloading The ASP Enterprise Manager, which is a web based toolwhich allows you to do many Enterprise Manager type tasks in MSDEwithout SQLEM.
http://www.aspenterprisemanager.com/
Jason

Sunday, February 19, 2012

dollar signs at the end of tables

Anyone know what's with dollar signs at the end of tables? One of my
clients has been "messing around" with his database, and I know he hasn't
got a clue. So now all the tables have been duplicated with the duplicates
having dollar signs at the end of the tables.
ex.
tblMytable
tblMytable$
Thanks,
JonIt's not actually my database, it's one of my clients, and I have absolutly
no idea what he did.
Thanks for the post though :-)
"Chinna Kondaveeti" <ckondaveeti@.hotmail.com> wrote in message
news:0d7201c36699$eaf99340$a001280a@.phx.gbl...
> I am not sure how they got in your database. But, usually
> when we export the excel workbooks using DTS, and if you
> choose the option create table and load the data, it will
> create a table with the worksheet name followed by $ (e.g.
> sheet1$ etc.)
> Thanks
> Chinna.
> >--Original Message--
> >Anyone know what's with dollar signs at the end of
> tables? One of my
> >clients has been "messing around" with his database, and
> I know he hasn't
> >got a clue. So now all the tables have been duplicated
> with the duplicates
> >having dollar signs at the end of the tables.
> >
> >ex.
> >
> >tblMytable
> >tblMytable$
> >
> >Thanks,
> >
> >Jon
> >
> >
> >.
> >|||May be MS access also puts duplicates, if you try to
connect to SQL Server database and try to save the tables.
Thanks
Chinna.
>--Original Message--
>Anyone know what's with dollar signs at the end of
tables? One of my
>clients has been "messing around" with his database, and
I know he hasn't
>got a clue. So now all the tables have been duplicated
with the duplicates
>having dollar signs at the end of the tables.
>ex.
>tblMytable
>tblMytable$
>Thanks,
>Jon
>
>.
>|||On Tue, 19 Aug 2003 17:39:03 -0400, "Jonathan Williams"
<anon@.covad.net> wrote:
>It's not actually my database, it's one of my clients, and I have absolutly
>no idea what he did.
>Thanks for the post though :-)
Hmm the further thought here would be... " have you actually asked him
what the f** he did?"
Al
>
>"Chinna Kondaveeti" <ckondaveeti@.hotmail.com> wrote in message
>news:0d7201c36699$eaf99340$a001280a@.phx.gbl...
>> I am not sure how they got in your database. But, usually
>> when we export the excel workbooks using DTS, and if you
>> choose the option create table and load the data, it will
>> create a table with the worksheet name followed by $ (e.g.
>> sheet1$ etc.)
>> Thanks
>> Chinna.
>> >--Original Message--
>> >Anyone know what's with dollar signs at the end of
>> tables? One of my
>> >clients has been "messing around" with his database, and
>> I know he hasn't
>> >got a clue. So now all the tables have been duplicated
>> with the duplicates
>> >having dollar signs at the end of the tables.
>> >
>> >ex.
>> >
>> >tblMytable
>> >tblMytable$
>> >
>> >Thanks,
>> >
>> >Jon
>> >
>> >
>> >.
>> >
>

Friday, February 17, 2012

Doing Math on Tables

Hello everyone:

I have a database for one of my websites, a picture rating site. Anyways, right now there are quicte a few tables, and I was wondering how to give the server a break and was wondering if this was possible:

Basicly I have a members table, and a votes table. Members will rate other users pcitures on a scale of one to ten, then the votes will be inserted into the votes table. The only problem with this is that calcuating all the votes a user has can put a straing on the server. I was wondering if it would be possible to create a math column in the members table that would automaticly figure out the users average and having it stored in a field in the members table, so all I would have to do is query the members average located in the mebers table, rather than tallying all the votes in the votes table for each member.

Hope this makes sense, a tutorial or any suggestions would be great!

ThanksYou should be able to add 3 columns to your Members table to help with this: TotalVotes, TotalScore, and AverageScore. And then you can add a trigger to your Votes table which would update these columns in the Members table each time a Votes record is added/updated/deleted.

You can see what Books Online has to say aboutTriggers. And here's a little overview which gives a friendly overview of triggers:The Trouble with Triggers.

I might add that I am completely paranoid about this approach :-) I would want to periodically refresh these fields in the Members table (probably with a SQL job that runs nightly) to make sure the data stays in sync.

Terri

Doing a lookup between tables

I have two tables, one is a list of offered classes (class_offer) and a list of avalaible classes (course).

I need to find which courses are not being offered.

This is what I have now. It returns all the course rows if they match or not. I don't understand why this does not work. I am comparing the primary key of the course to equivalent values in the class_offer table.

select distinct course.course_name from
course join class_offer
on
course.course_no != class_offer.course_no
and
course.dept_no != class_offer.dept_no

DDL's:

CREATE TABLE COURSE
(
COURSE_NO CHAR(3) not null,
DEPT_NO CHAR(3) not null,
COURSE_NAME VARCHAR2(30),
CREDIT_HOUR NUMBER(3),
CONSTRAINT COURSE_PK PRIMARY KEY (COURSE_NO,DEPT_NO)
);

ALTER TABLE COURSE
ADD CONSTRAINT FK_COURSE
FOREIGN KEY (DEPT_NO)
REFERENCES DEPARTMENT(DEPT_NO);

CREATE TABLE CLASS_OFFER
(
COURSE_NO CHAR(3) not null,
DEPT_NO CHAR(3) not null,
SECTION_NO CHAR(3) not null,
YEAR NUMBER(4) not null,
TIME CHAR(8),
LOCATION VARCHAR2(10),
FAC_NO CHAR(11),
CONSTRAINT CLASS_OFFER_PK PRIMARY KEY (COURSE_NO,DEPT_NO,SECTION_NO,YEAR)
);

ALTER TABLE CLASS_OFFER
ADD CONSTRAINT FK_OFFER_C
FOREIGN KEY
(
COURSE_NO,
DEPT_NO
)
REFERENCES COURSE
(
COURSE_NO,
DEPT_NO
);
ALTER TABLE CLASS_OFFER
ADD CONSTRAINT FK_OFFER_FAC
FOREIGN KEY (FAC_NO)
REFERENCES FACULTY(FAC_ID);you want a LEFT OUTER JOIN with a test in the WHERE clause for NULL in the join column of the right table|||This works, but it's the opposite of what I am looking for.

select distinct course.course_name from
course left outer join class_offer
on
course.course_no = class_offer.course_no and course.dept_no = class_offer.dept_no
where
class_offer.course_no is not null and class_offer.dept_no is not null;

When I replace the = with != it does not give me the correct response.|||you want IS NULL, not IS NOT NULL

and you don't need the DISTINCT|||It works now, thank you for your help.

Thing is, I am not highly proficiant in sql. I would like to be, since I do a lot of JDBC programming. So I am interested in how this query works. As a C++\Java programmer, I think in terms of multiple method calls to get an answer. In sql, all the steps are in one call. So I do not fully grasp how to build a sql call.|||practice, practice, practice

:cool:

Doing a CONTAINS search on multiple tables and columns combined.

I want to do a CONTAINS search on several columns combined.
This example searches each column separately, so that a record is not
included that has one of the search terms in the Desired Position and the
other two search terms in a section body.
SET @.SearchPhrase = 'Engineer AND SQL AND VB'
SELECT DISTINCT
dbo.tblResumes.ResumeID
, dbo.tblResumes.DesiredPosition
FROM
dbo.tblResumes LEFT OUTER JOIN
dbo.tblResumeSections ON dbo.tblResumes.ResumeID =
dbo.tblResumeSections.ResumeID
WHERE (CONTAINS(dbo.tblResumes.DesiredPosition, @.SearchPhrase)
OR CONTAINS(dbo.tblResumeSections.SectionTitle, @.SearchPhrase)
OR CONTAINS(dbo.tblResumeSections.Body, @.SearchPhrase))
How could I return a resume that has all three terms, but not in any one
column?
Also, I don't understand how the search works when their are several
tblResumeSections records for one tblResumes record. Does it search each
section record?
I am grateful for any suggestions.
As I've played with this in light of other recent similar posts, the only
approach I can see at this point is to create the query in code and send it
to the database server. This allows me to dynamically build the query to
allow for a variable number of search terms.
This must be a very common search and newsgroup queston: how to do an 'AND'
search invoving multiple tables and columns where all of a variable number
of search terms must be found in a row, but not any one column..
I can't find a way to do this with FULL TEXT searches in a stored procedure
so far. I get an error if I try to concatenate columns in a CONTAINS search
as below.
Again, any suggestions are very welcome.
The following query is constrcted in code on the web page and does a LIKE
search on a concatenation of the relevant columns. It works but falls short
in that a resume that has the search terms in different sections (child
table) is not returned. But it seems the best I can do for now.
DECLARE @.SearchPhrase VarChar(50)
, @.Role VarChar(15)
SET @.SearchPhrase = 'SQL AND VB AND Engineer'
SET @.Role = 'Job Seeker'
SELECT DISTINCT
dbo.tblResumes.ResumeID
, dbo.tblResumes.DesiredPosition
, dbo.tblPostionTypes.Abbr AS PType
, dbo.tblContacts.FirstName + ' ' + dbo.tblContacts.LastName AS
JobSeekerName
, dbo.tblResumes.DateRevised AS Posted
, dbo.tblContacts.City + ', ' + dbo.tblContacts.State AS CityState
FROM
dbo.tblResumes INNER JOIN
dbo.tblContacts ON dbo.tblResumes.ContactID = dbo.tblContacts.ContactID
INNER JOIN
dbo.tblPostionTypes ON dbo.tblResumes.PositionTypeID =
dbo.tblPostionTypes.PositionTypeID LEFT OUTER JOIN
dbo.tblResumeSections ON dbo.tblResumes.ResumeID =
dbo.tblResumeSections.ResumeID LEFT OUTER JOIN
dbo.tblExperiences ON dbo.tblResumeSections.ResSectionID =
dbo.tblExperiences.ResSectionID LEFT OUTER JOIN
dbo.tblQualifications ON dbo.tblResumes.ResumeID =
dbo.tblQualifications.ResumeID
WHERE dbo.tblResumes.DateStart < GETDATE()
AND dbo.tblResumes.DateStop > GETDATE()
AND dbo.tblResumes.Deleted Is Null
AND dbo.tblResumes.Active = 1
AND dbo.tblResumes.Approved = 1
AND dbo.tblContacts.Active = 1
AND dbo.tblContacts.Approved = 1
AND dbo.tblContacts.Role = @.Role
-- Keyword tests
AND dbo.tblResumes.DesiredPosition + ' ' +
dbo.tblResumeSections.SectionTitle + ' ' + dbo.tblResumeSections.Body LIKE
'%SQL%'
AND dbo.tblResumes.DesiredPosition + ' ' +
dbo.tblResumeSections.SectionTitle + ' ' + dbo.tblResumeSections.Body LIKE
'%VB%'
AND dbo.tblResumes.DesiredPosition + ' ' +
dbo.tblResumeSections.SectionTitle + ' ' + dbo.tblResumeSections.Body LIKE
'%Engineer%'
"GM" <gmdevREMOVE@.starband.net> wrote in message
news:OiI%23kzSREHA.3140@.tk2msftngp13.phx.gbl...
> I want to do a CONTAINS search on several columns combined.
> This example searches each column separately, so that a record is not
> included that has one of the search terms in the Desired Position and the
> other two search terms in a section body.
> SET @.SearchPhrase = 'Engineer AND SQL AND VB'
> SELECT DISTINCT
> dbo.tblResumes.ResumeID
> , dbo.tblResumes.DesiredPosition
> FROM
> dbo.tblResumes LEFT OUTER JOIN
> dbo.tblResumeSections ON dbo.tblResumes.ResumeID =
> dbo.tblResumeSections.ResumeID
> WHERE (CONTAINS(dbo.tblResumes.DesiredPosition, @.SearchPhrase)
> OR CONTAINS(dbo.tblResumeSections.SectionTitle, @.SearchPhrase)
> OR CONTAINS(dbo.tblResumeSections.Body, @.SearchPhrase))
> How could I return a resume that has all three terms, but not in any one
> column?
>
> Also, I don't understand how the search works when their are several
> tblResumeSections records for one tblResumes record. Does it search each
> section record?
> I am grateful for any suggestions.
>

Tuesday, February 14, 2012

Does truncate and API Load invalidate statistics

As part of my data warehouse nightly build, I truncate my tables in my
target database.
As example, I find it is much quicker to do a bulk API load of 13M
records and to do an update/insert of 100K rows. I also drop the
indexes before the builds and reindex after. Thats an aside.
What I am wondering is how is this impacting the statistics? Do I need
to update them?
Not well versed on statistics and any data is welcomed.
Thanks
Robrcamarda (robc390@.hotmail.com) writes:

Quote:

Originally Posted by

As part of my data warehouse nightly build, I truncate my tables in my
target database.
As example, I find it is much quicker to do a bulk API load of 13M
records and to do an update/insert of 100K rows. I also drop the
indexes before the builds and reindex after. Thats an aside.
What I am wondering is how is this impacting the statistics? Do I need
to update them?


When an indexes added, statistics based a full scan is added for that
index, so you are fairly safe.

Would could matter is statistics of non-indexed columns. These you lose
when you truncate the tables. These statistics are less essential than
index on indexed columns, but there are queries where they may be useful.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx