Dec-12-2017, 10:37 PM
Sorry, I put the T-SQL statements inside Python code.
Here is my question again:
I am using SQL Server 2017 to save people's information, I created a simple data table [People] in [mydb] database
CREATE TABLE [dbo].[People] (
[ID] [int] NOT NULL,
[Name] [nvarchar](40) NOT NULL,
[Age] [int] NOT NULL,
[Height] [int] NOT NULL,
[Weight] [int] NOT NULL
CONSTRAINT PK_People PRIMARY KEY(ID))
GO
I have the following Python code to generate some records of people, and I want to save all such records into SQL Server 2017 database. The database name is: mydb, and the data table name is: [People].
I want to use pyodbc or whatever software package to insert all the people records into [People] data table.
I also have a primary key [ID], I want to use the order in the list of people to be the primary key, for the above example, the ID could be: 1, 2, 3, etc...
I can't figure out how to do the bulk insert into SQL Server 2017 database, I think since SQL Server 2017 has native support for python, so this could be possible.
Please advise!
Thanks,
Here is my question again:
I am using SQL Server 2017 to save people's information, I created a simple data table [People] in [mydb] database
CREATE TABLE [dbo].[People] (
[ID] [int] NOT NULL,
[Name] [nvarchar](40) NOT NULL,
[Age] [int] NOT NULL,
[Height] [int] NOT NULL,
[Weight] [int] NOT NULL
CONSTRAINT PK_People PRIMARY KEY(ID))
GO
I have the following Python code to generate some records of people, and I want to save all such records into SQL Server 2017 database. The database name is: mydb, and the data table name is: [People].
import collections Person = collections.namedtuple('Person', ['Name', 'Age', 'Height', 'Weight']) person1 = Person(Name='Bob', Age=55, Height=165, Weight=70) person2 = Person(Name='Doe', Age=45, Height=185, Weight=90) person3 = Person(Name='John', Age=50, Height=175, Weight=85) ...... person30000 = Person(Name='XYZ', Age=30, Height=160, Weight=65) people = [person1, person2, person3, ... person30000]I have 30,000 records of people like the above, which is a list of namedtuple.
I want to use pyodbc or whatever software package to insert all the people records into [People] data table.
I also have a primary key [ID], I want to use the order in the list of people to be the primary key, for the above example, the ID could be: 1, 2, 3, etc...
I can't figure out how to do the bulk insert into SQL Server 2017 database, I think since SQL Server 2017 has native support for python, so this could be possible.
Please advise!
Thanks,