Fix orphaned users in MSSQL
Run this in the Query Analyzer (make sure the right database is selected first).
sp_change_users_login 'auto_fix', 'UserName'
TextSnippets > chrelad > mssql
2827 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)
Christopher Dale
sp_change_users_login 'auto_fix', 'UserName'
-- The syntax for pulling a certain part of a DATETIME is: -- -- CONVERT(date_type[(length)],expression[,style]) -- -- The available styles are as follows: -- -- NULL Jun 24 2001 9:48PM -- 1 06/24/01 -- 101 06/24/2001 -- 2 01.06.24 -- 104 24.06.2001 -- 108 21:48:00 -- 112 20010624 -- 121 2001-06-24 21:48:00.000 -- Some example usage: SELECT CONVERT(DATETIME,GETDATE(),112) as date -- Will output in YYYYMMDD format SELECT CONVERT(DATETIME,client.birthday,101) as birthday -- Will output in MM/DD/YYYY format
// MySQL limit clause SELECT emp_id,lname,fname FROM employee LIMIT 20,10 // MSSQL equivelent select * from ( select top 10 emp_id,lname,fname from ( select top 30 emp_id,lname,fname from employee order by lname asc ) as newtbl order by lname desc ) as newtbl2 order by lname asc
IF NOT EXISTS ( SELECT * FROM [information_schema].[columns] WHERE table_name = 'Customer' AND table_schema = 'dbo' AND column_name = 'FavoriteColorId' ) BEGIN ALTER TABLE [dbo].[Customer] ADD FavoriteColorId int
SELECT * FROM information_schema.columns WHERE table_name = 'Customers'