import pyodbc as p server = 'ServerName' database = 'DatabaseName' userid = 'UserName' pwd = 'UserPassword' connStr = ( r'DRIVER={SQL Server};SERVER=' + server + ';DATABASE=' + database + ';' + 'UID=' + userid + ';PWD='+pwd+';') lst = [] conn = p.connect(connStr) dbCursor = conn.cursor() sql = ('SELECT ColumnName AS FieldValue FROM tblTableName') dbCursor = conn.cursor() dbCursor.execute(sql) for row in dbCursor: lst.append(row.FieldValue) conn.close() print lst
Thursday, December 9, 2010
Read a SQL Server table into a list using Python + pyodbc
Labels: Python, SQL Server, SQL Server Tip
Friday, December 3, 2010
Shrinking Truncate Log File
USE YourDatabaseName
GO
--Run this script to get your TransactionLogName
SELECT * FROM sys.sysfiles
GO
DBCC SHRINKFILE(TransactionLogName, 1)
BACKUP LOG YourDatabaseName WITH TRUNCATE_ONLY
DBCC SHRINKFILE(TransactionLogName, 1)
GO
Labels: DBA Tasks, SQL Server, SQL Server Tip
Subscribe to:
Posts (Atom)