Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating scripts based on condition

The inserts of a certain table(s) can be generated by using SQL Server Management Studio by right clicking on the database -> tasks -> generate scripts, choosing the tables and finally selecting data only. However the table gets bigger with time and I need only the inserts with a certain condition which would only return only a part of the data in that table.

Example: there is a table

FlightTickets
(
    TicketId(PK), 
    BuyerId(FK to buyers), 
    FlightId(FK to Flights)
)

and I only need the insert scripts with condition FlightId = 12345.

Is it possible to be done in SQL Server Management Studio or do I have to write some in C# to deal with that?

like image 623
Andrius Naruševičius Avatar asked Oct 29 '25 01:10

Andrius Naruševičius


1 Answers

You can try database -> tasks --> Import Data --> [then choose source and destination]--> [write a query to specify the data to transfer] option --> then write your query with filter [ where flightid=12345]

like image 168
ram_sql Avatar answered Oct 30 '25 16:10

ram_sql



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!