Save or not the commands used in Mysql

Asked

Viewed 412 times

2

When you create a Mysql code and run, that code after running, do you need to save it or not? Or after running can you forget it? I’m talking about the commands that create table, update, insert, etc.

  • You may or may not save. It depends a lot on the context, if you save it you can use as a basis to create other scripts or if you don’t write again.

  • Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site

5 answers

3

No need, but you can write to some file to use again if you want. One thing is not related to another.

I wouldn’t exactly call code what you do directly in Mysql, it is, but in general they are loose commands. And so what you’re doing probably won’t be used the same again.

On te that you are using a command processor, be it the one provided by Mysql itself in command line or another like the Workbench that seems to be using.

If you create a command that you think is complex enough and worth using again you can save to a file with extension .sql and then call you to perform equal.

It is possible to record all commands, even often it is recorded to function as a script to play the same commands in another location, another instance of the database. But it is more common than these scripts be prepared later and not as soon as you use a command to test if that’s what you want.

In general this type of thing is more common when programming in another language to create a code that manipulates the database, then the SQL command goes inside the code.

It is also possible to use these commands in stored Procedure, but this is already much more advanced.

0

When executing command in a database, be it any one (SQL server, Mysql and etc) most of the changes performed are saved in DB. Except when certain processes are actually temporary(a slightly more advanced subject), when you run, Insert, update, delete, among others. This information is stored in a fixed form in the database, which will be lost if not saved, will be the query that are the codes you write, example:

Select * from table X

update table X set field Y = 10

I hope I’ve helped!

0

Mysql is roughly a data manager, it alone I would say would not serve for something practical, you should associate it to a programming language to display the results obtained through the Mysql commands, in this way in this language you "save" the commands and executes whenever you need by modifying only the values of the parameters.

Example:

SELECT * FROM TABELA_A WHERE (CODKEY = :CODIGO)

In this case you would only change the value of ":CODE" and have specific record data.

Commands such as CREATE DATABASE, CREATE TABLE, CREATE INDEX and others are executed only to create tables and indexes and the like, not being necessary to write them, already commands such as INSERT, DELETE, UPDATE and SELECT are widely used in the daily life of an application so as stated above it is only worth recording and modifying only the parameters.

I hope I’ve helped.

0

Right now I’m doing a simple CRUD (Create, Read, Update and Delete) project that uses Python and SQL. I saved the script made for the creation of the Database and still commented each line.

The commands and/or changes that will occur, will be made by the programming language, in my case Python. If you need to make a query or a change that you would make directly by a query, without the language, I think it would be valid to save (even in the original script)

I think it’s relevant that you save these things because up front you can help yourself or someone else by giving them a basis on how it works. It is also a documentation of the project itself and can also help explain or understand when and why the change occurred (if someone else enters the project or application).

But saving or not, it won’t make any difference in your program. And you still get that code again by making a dump (backup), taking together the values that have been added over time.

Repository of my project (I started this week):

inserir a descrição da imagem aqui

Remember that, all projects that you will participate/do, always have, or in the future will have, more people involved. The more organized your application is, the better the maintenance and understanding of it.

-1

When you create a mysql code and run, that code after running, you need to save it or not ?

No. No need. However, you can even save the file and then use it in another activity. Commands bring changes to your database. Pay attention and be careful what you are doing, especially with the command Drop Table.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.