Questions tagged as 'sql'

3
answers

How to round a number to the highest value in Mysql?

I was doing some testing in MySQL and then came the need to have to round a number to the largest. It would be something like: if($numero == 1.5){ $numero = 2; } Although I could do this, I wanted to avoid making if / else...
asked by 13.09.2017 / 16:16
1
answer

Can I change more than one record at a time?

This is the code: UPDATE PESSOAS SET COR = ('Pardo') WHERE ID = 1; But I have 2 more records to do the same procedure, would you do it all at once by adding ID ?     
asked by 27.10.2017 / 19:55
2
answers

Prevent DROP TABLE

I would like to prevent deletions in a table in SQLite. CREATE TRIGGER nao_deletar_tabela BEFORE DELETE ON tabela BEGIN SELECT RAISE(IGNORE); END; It worked! Whenever a DELETE is executed, nothing happens. The problem and...
asked by 31.10.2014 / 12:39
1
answer

Return last value entered in the table where the value is not identity?

I would like to return the last value of the primary key inserted in the table, but my primary key is CPF so I can not use SELECT SCOPE_IDENTITY() .     
asked by 24.04.2017 / 16:24
1
answer

How to mount a SELECT to return the last status change of each id?

I have the following table: status_faturas id_fatura | status | data ---------------------------------------- XX-XX-XX | 3 | 2017-01-04 21:00:24 XX-XX-XX | 2 | 2017-01-02 11:10:20 YY-YY-YY | 4 | 2017-01-04 21:00:24 YY-YY-Y...
asked by 05.01.2017 / 00:08
3
answers

Inserting registry and retrieving ID generated by SQL Server 2012

I want to insert a record into a table, retrieve the ID that was generated by AUTO_INCREMENT and insert records into other tables, using that ID. But, I want to do this all using BeginTransaction . How could I do this? I'm doi...
asked by 23.11.2015 / 12:49
2
answers

Delete all tables from a bank at once

Is there a way I can delete an entire database at a single time? It is not drop , it is to delete only the records of all the tables belonging to the database.     
asked by 23.02.2015 / 19:46
4
answers

Array of SQL conditions - PHP

Good afternoon, I am sending a search filter for my DB, and I want to make these conditions within an array, for example: $condicoes = array(); $nome = $_GET['nome']; if (!empty($nome)) { $condicoes = ("nome" => $nome); } $tipoAnimal =...
asked by 04.09.2014 / 21:23
3
answers

Is it a good practice to use composite keys as a primary key? [duplicate]

I do not have much knowledge in database design. I have tried to hone myself better and am looking for best practices on how to create and structure tables. I currently create binding tables and combine the ID's of each table by turning the...
asked by 08.08.2016 / 16:54
2
answers

How to format a DateTime field in the Brazilian format dd / MM / yyyy?

I would like to format the DataAfr and DataTrm fields of type DATETIME , in Brazilian date format dd / MM / YYYY instead of the American format yyyy-mm-dd hh: mm: ss SELECT e.NmrCnt AS [Contrato] ,e.NmrSeri...
asked by 21.09.2016 / 14:55