Is there anyway I can get the DDL from SQL Server in Python ? Any help is appreciated. The loop doesn't print other details that are shown from the image and I don't understand how can I implement loop properly to print/access the other data that was shown in the image above. This result is the first table from the result in the image given above. I only see the first table in the result: ('tablename', 'dbo', 'user table', datetime.datetime(2020, 8, 27, 9, 51, 11, 213000)) > cursor.execute("exec sp_help 'dbo.tablename'")īut if I iterate the result from cursor as below: > for r in cursor: > conn = nnect(host='Server\\Server',user='user', password='pwd',database='dbname') Create Tables : -Company Table Create Table Compan圓 ( CompanyID number Constraint mycomp3id Primary Key, Name varchar2 (200) Constraint mycomp3name Unique,Email varchar2 (300),Website varchar2 (400), ContactInformation varchar2 (150), Username varchar2 (30) default'user2003', Password varchar2 (20) Constraint mypassword3 Not Null ch. So I ran the proc in python as below: > import pymssql In the image the proc: sp_help returns lot of data and column names are present in the second table of the result & the key constraints are present in the last table of the result.Īll of this result is found in Sql Server Studio. So I ran sp_help in the Sql Server management studio as below: exec sp_help 'dbo.tablename' When I run the show create table as below, I get syntax error as below: import pyodbcĬnxn = nnect("Driver= "Ĭursor.execute('show create table dbname.tablename')Įrror: pyodbc.ProgrammingError: ('42000', " Incorrect syntax near 'tablename'. One of the reason I am trying to generate the DDL is to get the DDL and create them in my target DB, (it is in snowflake & I am writing code to create the tables as well) get the PRIMARY & UNIQUE KEYS from the table and use them in my code (some requriement). ![]() ![]() So I explored online for some help and found out that we can run the proc: sp_help as exec sp_help schema.tablename. I tried to run the statement: show create table schema.table which didn't work. I am trying to generate a DDL of a table in SQL Server using Python.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |