T SQL2
T-sql example source2
[1] to be granted permissions from query analyzer -- to be granted permissions from query analyzer

USE <Your database name>
GO

-- This example adds an account for the Windows NT user Corporate\GeorgeW to the current database and gives it the name Georgie.

EXEC sp_grantdbaccess 'Corporate\GeorgeW', 'Georgie'



Only members of the sysadmin fixed server role, the db_accessadmin and db_owner fixed da .....
[2] drop (delete) user from query analyzer -- drop (delete) user from query analyzer

USE <Your database name>
GO

--This example removes the user Albert from the current database.
EXEC sp_dropuser 'Albert'


-- Only members of the sysadmin fixed server role, the db_owner or db_accessadmin fixed database roles can execute sp_dropuser.

sp_dropuser
Removes a Microsoft® SQL Server™ user or M .....
[3] add user using store procedure from query analyzer -- add user using store procedure from query analyzer


CREATE PROCEDURE sp_MyAddSystemUser (@UserName varchar(50), @DBName varchar(20) =
"", @RoleName varchar(20) = "" )

AS

--do any other sort of logic here

DECLARE @rv int

EXEC @rv = sp_AddUser @UserName, @DBName, @RoleName

RETURN @rv

[4] add user from query analyzer -- add user in query analyzer

USE <Your database name>
GO

EXEC sp_AddUser 'YourName', 'optional name in db', 'optional role/group name to be a part of'

-- This example adds the user Victoria to the existing fort_mudge role in the current database, using the existing login Victoria.
-- EXEC sp_adduser 'Victoria', 'Victoria', 'fort_mudge'

-- This exam .....
[5] Script to Reverse Engineer SQL Server Object Role Permissions Script to Reverse Engineer SQL Server Object Role Permissions

--Written By Bradley Morris
--In Query Analyzer be sure to go to
--Query -> Current Connection Options -> Advanced (Tab)
--and set Maximum characters per column
--to a high number, such as 10000, so
--that all the code will be displayed.



DECLARE @DatabaseRoleName [sysname]
--SET @Datab .....
[6] Script to Reverse Engineer SQL Server Object User Permissions Script to Reverse Engineer SQL Server Object User Permissions

--Written By Bradley Morris
--In Query Analyzer be sure to go to
--Query -> Current Connection Options -> Advanced (Tab)
--and set Maximum characters per column
--to a high number, such as 10000, so
--that all the code will be displayed.



DECLARE @DatabaseUserName [sysname]
SET @Databas .....
[7] How to send and receive e-mail with the SQL Mail feature . Click Start, and then click Enterprise Manager.
. Expand Microsoft SQL Servers.
. Expand a server group, expand a server, and then expand Support Services.
. Right-click SQL Mail, and then click Properties.
. In the Profile name box, click the account you configured for SQL Mail 2000, and then click Test.
Click OK.


[8] 한줄 주석처리는 -- 을 이용한다

-- EXEC sp_changeobjectowner 'IUSR_DBM-HYOUNG.FORUM_A_REPLY', 'dbo'
-- 이줄도 주석;


DECLARE @old sysname, @new sysname, @sql varchar(1000)



SELECT

-- @old = 'put_your_old_user_name_here'
-- 이 줄은 주석처리 되어 실행되지 않는다.

@old = 'IUSR_DBM-HYOUNG'

, @new = 'dbo'

, @sql = '

IF EXISTS (SELECT NULL FROM INFO .....
[9] 테이블 소유자(owner change) 바꾸기

-- EXEC sp_changeobjectowner 'IUSR_DBM-HYOUNG.FORUM_A_REPLY', 'dbo'



DECLARE @old sysname, @new sysname, @sql varchar(1000)



SELECT

-- @old = 'put_your_old_user_name_here'

@old = 'IUSR_DBM-HYOUNG'

, @new = 'dbo'

, @sql = '

IF EXISTS (SELECT NULL FROM INFORMATION_SCHEMA.TABLES

WHERE
[10] sql 안에서 문자열 찾기 SET @COUNT = 5
WHILE (@COUNT>0)
BEGIN
-------------------------------------------------------------------------------------------------
UPDATE EDIFileMapping_830
SET PartId = LEFT(PartID, CHARINDEX('~', PartId)-1) + RIGHT(PartID, LEN(PartID)-CHARINDEX('~', PartId))
WHERE CHARINDEX('~', PartId) > 0

SET @COUNT = @COUNT - 1
----------------------- .....
Javascript Source List :