select name, RoleName FROM sys.sysmembers sm
JOIN
( select 'RoleName' = name, 'RoleId' = uid, 'IsAppRole' = isapprole
from sysusers where issqlrole = 1 or isapprole = 1 ) roles
ON sm.groupuid=roles.RoleID
JOIN
( select * from master.sys.sysusers where islogin=1 ) logins
ON logins.uid=sm.memberuid;
четвер, 29 жовтня 2009 р.
MSSQL: users and roles
Metadata in SQL Server
"Depending on your viewpoint, metadata is used to add context and understanding about data that users are accessing, or it can be used to hide complexity from end users who are not required to know or understand the technical details of data. Metadata can also be used by systems to determine data types, to reveal the structure and relationships between data, or to determine if and when data last changed, and what changes were made to data. Metadata is also used by applications and systems to perform type checking, data validation, and formatting of data." ( TechNet )
Metadata is managed with the folllowing stored procedures:
Add an extended property | sp_addextendedproperty |
| Delete an extended property | sp_dropextendedproperty |
| Update an extended property | sp_updateextendedproperty |
| View an extended property | fn_listextendedproperty sys.extended_properties |
Here is an example of extended property update:
USE AdventureWorks;
GO
EXEC sys.sp_updateextendedproperty
@name = N'MS_Description',
@value = N'New Description for the Address table',
@level0type = N'SCHEMA', @level0name = Person,
@level1type = N'TABLE', @level1name = Address;
GO
You can view the metadata with SELECT statement but you cannot modify it using UPDATE:
sp_configure 'allow updates',1
update sys.extended_properties set value='111' WHERE name='Purpose';
Result:
Ad hoc updates to system catalogs are not allowed.
We can not update neither system tables nor system views. This is regardless whether we've set "allow updates" or not. Use special procedures.
You can read more about metadata at http://msdn.microsoft.com/en-us/library/cc966384.aspx#ECAA
середа, 16 вересня 2009 р.
How to add 1 day to the date
Oracle : SYSTIMESTAMP+NUMTODSINTERVAL(1,'day')
DB2 : CURRENT TIMESTAMP+1 DAY
PostgreSQL : LOCALTIMESTAMP+INTERVAL '1 day'
вівторок, 15 вересня 2009 р.
BCP and problems with Unicode
> bcp madhu1.dbo.testunicode in "D:\testunicode.txt" -S ABCSqlSrv -U sa -P sa -f "d:\fmt.txt"
Starting copy...
SQLState = HY000, NativeError = 0
Error = [Microsoft][SQL Native Client]Unexpected EOF encountered in BCP data-file
0 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total : 1
contents of testunicode.txt are :
मधुकर|pune|33
राहुल|pune|36
==========================
contents of format file fmt.txt are
8.0
3
1 SQLNCHAR 0 0 "|" 1 name SQL_Latin1_General_CP1_CI_AS
2 SQLNCHAR 0 0 "|" 2 address SQL_Latin1_General_CP1_CI_AS
3 SQLNCHAR 0 0 "\r\n" 3 age SQL_Latin1_General_CP1_CI_AS
================
However, this can be avoided by using -w option and removing -f option
Sphinx example for PHP
Have fun.
Resetting forgotten root password
1) kill mysqld
2) run
mysqld_safe –skip-grant-tables &
mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD(’newrootpassword’) WHERE User=’root’;
mysql> FLUSH PRIVILEGES;
3) kill the started MySQL server
4) restart it
Resetting forgotten root password
1) kill mysqld
2) run
mysqld_safe –skip-grant-tables &
mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD(’newrootpassword’) WHERE User=’root’;
mysql> FLUSH PRIVILEGES;
3) kill the started MySQL server
4) restart it