2007年4月20日星期五

Look the microsoft forums find this question !

question:
Can I use SQLHelper.cs in win forms?
I have used a lot SQLHelper.cs in web forms and wondering would that make any difference using in win forms.
Thanks
answer:
You can see the msdn article The Enterprise Library Data Access Application Block, Part 2(http://msdn.microsoft.com/msdnmag/issues/05/08/DataPoints/)that provides a demo using Winforms.

Today i'm join Adsense

today this blog joined google adsense ,google tell me do't arouse any body click the Advertisement!shit i think no body shall click the advertisment!

2007年4月19日星期四

Size of space used for data file For Microsoft® SQL Server™

how get the size of data used in the mdf file of a database, KB or MB, into a variable?

use the following query !may help you

--------------------------------------------------
declare @pages int
create table #spt_space
(
rows int null,
reserved dec(15) null,
data dec(15) null,
indexp dec(15) null,
unused dec(15) null
)

insert into #spt_space (reserved)
select sum(convert(dec(15),reserved))
from sysindexes
where indid in (0, 1, 255)


select @pages = sum(convert(dec(15),dpages))
from sysindexes
where indid < 2
select @pages = @pages + isnull(sum(convert(dec(15),used)), 0)
from sysindexes
where indid = 255
update #spt_space
set data = @pages


/* index: sum(used) where indid in (0, 1, 255) - data */
update #spt_space
set indexp = (select sum(convert(dec(15),used))
from sysindexes
where indid in (0, 1, 255))
- data

/* unused: sum(reserved) - sum(used) where indid in (0, 1, 255) */
update #spt_space
set unused = reserved
- (select sum(convert(dec(15),used))
from sysindexes
where indid in (0, 1, 255))

select reserved = ltrim(str(reserved * d.low / 1024.,15,0) +
' ' + 'KB'),
data = ltrim(str(data * d.low / 1024.,15,0) +
' ' + 'KB'),
index_size = ltrim(str(indexp * d.low / 1024.,15,0) +
' ' + 'KB'),
unused = ltrim(str(unused * d.low / 1024.,15,0) +
' ' + 'KB')
from #spt_space, master.dbo.spt_values d
where d.number = 1
and d.type = 'E'

a finance stock management FIFO Sql method

1.table
inStore

id,prodno,prodname,spec,amount,price
------------------------------------
1 01 Pen Blue 10 10.5
2 01 Pen Blue 20 10.5
3 01 Pen Blue 12 10.5
4 01 Pen Black 10 10.5
5 01 Pen Red 10 10.5



2.table
outstore
id,prodno,prodname,spec,amount,price
------------------------------------
1 01 Pen Blue 3 10.5
2 01 Pen Blue 4 10.5
3 01 Pen Black 8 10.5



Instore - OutStore and Grouped =
1 01 Pen Blue 35 10.5
1 01 Pen Black 2 10.5
1 01 Pen Red 10 10.5]


-------------------------------------
Use the following query


Select prodno, prodname, spec,sum(amount),max(price)

From

(
SELECT prodno, prodname, spec, amount, price FROM instore

Union ALL

SELECT prodno, prodname, spec, -amount, price FROM outstore

) as Data

Group By

prodno, prodname, spec

Schema, User and Login To understand what is Schema, User and Login on SQL Server.

Introduction
In Microsoft® SQL Server™, each database have Schema, User and Login. In this article we are going to see the basic difference between these objects.


Login Name
Login identifiers (Ids) are associated with users when they connect to Microsoft® SQL Server™ 2000. Login IDs are the accounts that control access to the SQL Server system. A user cannot connect to SQL Server without first specifying a valid login ID. Members of the sysadmin fixed server role define login IDs.


Purpose : It is used to connect the SQL server.


sp_addlogin (sql server authentication) sp_grantlogin (NT authentication)


User Name
A user identifier (ID) identifies a user within a database. All permissions and ownership of objects in the database are controlled by the user account. User accounts are specific to a database; the xyz user account in the sales database is different from the xyz user account in the inventory database, even though both accounts have the same ID. User IDs are defined by members of the db_owner fixed database role.


A login ID by itself does not give a user permissions to access objects in any databases. A login ID must be associated with a user ID in each database before anyone connecting with that login ID can access objects in the databases. If a login ID has not been explicitly associated with any user ID in a database, it is associated with the guest user ID. If a database has no guest user account, a login cannot access the database unless it has been associated with a valid user account.


When a user ID is defined, it is associated with a login ID. For example, a member of the db_owner role can associate the Microsoft® Windows® 2000 login NETDOMAIN\Joe with user ID abc in the sales database and user ID def in the employee database. The default is for the login ID and user ID to be the same.


Purpose : If specific login wants to access on specific database they should be added into the database.


sp_grantdbaccess


Schema Name

It is inside the database; specific to Table and View permission aginst to the User(not login). It will describe the permission(s) on the Table and View. In otherword it is inline permission statement while creating Tables and Views.


Purpose: You can grant permission while creating (or just before creating) the Table or View. Here there is no specific order where the grant statement should appear(ie, you can first give the permission before creating table or view).


CREATE SCHEMA AUTHORIZATION



Conclusion

So, the Top level is Login name, to connect the SQL Server, User Name is the access permission to the Database, Schema Names are inline access permissions while creating the database. Database objects are named using UserName.ObjectName. UserName and LoginName may not be identical. ie., you can change the UserName for any login name. By default the Username and LoginName are same. (ex. DBO is username of SA loginname)

Refrences

http://msdn2.microsoft.com/en-us/library/ms189462.aspx


Copped by Manivannan.D.Sekaran

2007年4月18日星期三

My wife have a fashion Zone Shop!

My girl friend Have a fashion Zone Shop!
Welcome for you!
http://www.sfzaa.com

My Friend Blog!

My friend Blog !http://www.peterlu.cn/
if you have interest we are greet for you!