How to replace a string in a SQL Server Table Column
It’s this easy: update my_table set path = replace(path, ‘oldstring’, ‘newstring’)
It’s this easy: update my_table set path = replace(path, ‘oldstring’, ‘newstring’)
No need for a separate SELECT… INSERT INTO table (name) OUTPUT Inserted.ID VALUES(‘bob’); This works for non-IDENTITY columns (such as GUIDs) too
You can use the sp_columns stored procedure: exec sp_columns MyTable
SELECT DATEADD(month, DATEDIFF(month, 0, @mydate), 0) AS StartOfMonth
You could also try EXISTS: SELECT EXISTS(SELECT * FROM table1 WHERE …) and per the documentation, you can SELECT anything. Traditionally, an EXISTS subquery starts with SELECT *, but it could begin with SELECT 5 or SELECT column1 or anything at all. MySQL ignores the SELECT list in such a subquery, so it makes no … Read more
Probably due to the way different sql dbms deal with schemas. Try the following For SQL Server: SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = ‘BASE TABLE’ AND TABLE_CATALOG=’dbName’ For MySQL: SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = ‘BASE TABLE’ AND TABLE_SCHEMA=’dbName’ For Oracle I think the equivalent would be to use DBA_TABLES.
One-to-one: Use a foreign key to the referenced table: student: student_id, first_name, last_name, address_id address: address_id, address, city, zipcode, student_id # you can have a # “link back” if you need You must also put a unique constraint on the foreign key column (addess.student_id) to prevent multiple rows in the child table (address) from relating … Read more
For this you can use limit select * from scores order by score desc limit 10 If performance is important (when is it not 😉 look for an index on score. Starting with version 8.4, you can also use the standard (SQL:2008) fetch first select * from scores order by score desc fetch first 10 … Read more
You can use DESCRIBE: DESCRIBE my_table; Or in newer versions you can use INFORMATION_SCHEMA: SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = ‘my_database’ AND TABLE_NAME = ‘my_table’; Or you can use SHOW COLUMNS: SHOW COLUMNS FROM my_table; Or to get column names with comma in a line: SELECT group_concat(COLUMN_NAME) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = ‘my_database’ AND … Read more
I accomplished the same goal by using a WITH clause, it’s nowhere near as elegant but can do the same thing. Though for this example it’s really overkill. I also don’t particularly recommend this. WITH myconstants (var1, var2) as ( values (5, ‘foo’) ) SELECT * FROM somewhere, myconstants WHERE something = var1 OR something_else … Read more