Coder Social home page Coder Social logo

sql-utils's Introduction

sql-utils

Datetime format yyyy/mm/dd hh:mm

CAST(CONVERT(CHAR(17),DataCadastro,113) AS datetime)

Datetime any formats

http://www.sqlinfo.net/sqlserver/sql_server_SELECT-Formatting_Date_Time.php

GET current PK inserted

SELECT CONVERT(INT, @@IDENTITY)

Find collumn

SELECT t.name AS table_name, SCHEMA_NAME(schema_id) AS schema_name, c.name AS column_name FROM sys.tables AS t INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID WHERE c.name LIKE '%FLAG%' ORDER BY schema_name, table_name;

Reset PK

DBCC CHECKIDENT ('PlanoConta', RESEED, 0)

**SELECT / INSERT

INSERT INTO TABELA1 SELECT * FROM TABELA2

Unable referential integrity

EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'

Enable referential integrity

EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'

Find objects

SELECT * FROM sysobjects WHERE type = 'U'

KILL transaction

SELECT trans.session_id as [Session ID], trans.transaction_id as [Transaction ID], tas.name as [Transaction Name], tds.database_id as [Database ID] FROM sys.dm_tran_active_transactions tas INNER JOIN sys.dm_tran_database_transactions tds ON (tas.transaction_id = tds.transaction_id ) INNER JOIN sys.dm_tran_session_transactions trans ON (trans.transaction_id=tas.transaction_id) WHERE trans.is_user_transaction = 1 -- user AND tas.transaction_state = 2-- active AND tds.database_transaction_begin_time IS NOT NULL

KILL [Session_ID]

Enable case sensitive

ALTER TABLE usuario ALTER COLUMN senha VARCHAR (50) COLLATE SQL_Latin1_General_CP1_CS_AS NOT NULL

Script for creating ASP.NET Session DB using SQL

DB ASPState

https://github.com/khaueviana/sql-utils/blob/master/DB-ASP-State.sql

Temp tables

https://github.com/khaueviana/sql-utils/blob/master/ASPState-tempdb.sql

sql-utils's People

Contributors

khaueviana avatar

Stargazers

Alexandre Oliveira avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.