How to check active transactions in SQL Server 2014?

Query with sys.sysprocesses SELECT * FROM sys.sysprocesses WHERE open_tran = 1 DBCC OPENTRAN : helps to identify active transactions that may be preventing log truncation. DBCC OPENTRAN displays information about the oldest active transaction and the oldest distributed and nondistributed replicated transactions, if any, within the transaction log of the specified database. Results are displayed … Read more

How to format a numeric column as phone number in SQL

This should do it: UPDATE TheTable SET PhoneNumber = SUBSTRING(PhoneNumber, 1, 3) + ‘-‘ + SUBSTRING(PhoneNumber, 4, 3) + ‘-‘ + SUBSTRING(PhoneNumber, 7, 4) Incorporated Kane’s suggestion, you can compute the phone number’s formatting at runtime. One possible approach would be to use scalar functions for this purpose (works in SQL Server): CREATE FUNCTION FormatPhoneNumber(@phoneNumber … Read more

unpacking a sql select into a pandas dataframe

You can pass a cursor object to the DataFrame constructor. For postgres: import psycopg2 conn = psycopg2.connect(“dbname=”db” user=”user” host=”host” password=’pass'”) cur = conn.cursor() cur.execute(“select instrument, price, date from my_prices”) df = DataFrame(cur.fetchall(), columns=[‘instrument’, ‘price’, ‘date’]) then set index like df.set_index(‘date’, drop=False) or directly: df.index = df[‘date’]

CREATE DATABASE using file in default path

Create the database ‘Documents’ and give file properties through an alter. USE [master] GO CREATE DATABASE [Documents] GO ALTER DATABASE [Documents] MODIFY FILE ( NAME = N’Documents’, SIZE = 512MB, MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ) GO ALTER DATABASE [Documents] MODIFY FILE ( NAME = N’Documents_log’, SIZE = 256MB, MAXSIZE = UNLIMITED, FILEGROWTH = … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)