SQL

SET Id autoincrement Mysql and MsSql

Mysql

ALTER TABLE `Table` AUTO_INCREMENT=18;

Mssql

DBCC CHECKIDENT ('table', RESEED, 71);

Kategoria: 

calendar

SET @start_date = CAST('2018-02-20 12:30:01' AS DATETIME);
SET @end_date = CAST('2018-02-20 14:29:59' AS DATETIME);
 
 
 
SELECT * FROM table
WHERE 
 
  (date_from > @start_date AND date_from < @end_date)
   OR 
  (date_to > @start_date AND date_from < @end_date)
  OR  
  (date_to > @start_date AND date_to < @end_date)
 
 
Kategoria: 

Find fields on all tables

SELECT DISTINCT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME IN ('columnA','ColumnB')
AND TABLE_SCHEMA='YourDatabase';

Kategoria: 

mysql to csv

 SELECT * FROM plugin_objects  INTO OUTFILE '/tmp/orders.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';

OR

CREATE TABLE () (SELECT data FROM other_table ) ENGINE=CSV  ;

When you create a CSV table, the server creates a table format file in the database directory. The file begins with the table name and has an .frm extension. The storage engine also creates a data file. Its name begins with the table name and has a .CSV extension. The data file is a plain text file. When you store data into the table, the storage engine saves it into the data file in comma-separated values format.
Kategoria: 

Delete without checking foreign key

SET foreign_key_checks = 0;
DELETE FROM...
SET foreign_key_checks = 1;
Kategoria: 
Subskrybuj SQL