How does the search_path influence identifier resolution and the “current schema”

What is the schema search path search_path? The manual: […] tables are often referred to by unqualified names, which consist of just the table name. The system determines which table is meant by following a search path, which is a list of schemas to look in. Bold emphasis mine. This explains identifier resolution. The “current … Read more

Create table variable in MySQL

They don’t exist in MySQL do they? Just use a temp table: CREATE PROCEDURE my_proc () BEGIN CREATE TEMPORARY TABLE TempTable (myid int, myfield varchar(100)); INSERT INTO TempTable SELECT tblid, tblfield FROM Table1; /* Do some more stuff …. */ From MySQL here “You can use the TEMPORARY keyword when creating a table. A TEMPORARY … Read more

Add a new table column to specific ordinal position in Microsoft SQL Server

You have to create a temp table that mirrors the original table’s schema but with the column order that you want, then copy the contents of the original to temp. Delete the original and rename the temp. This is what SQL Management Studio does behind the scenes. With a schema sync tool, you can generate … Read more

Count the Number of Tables in a SQL Server Database [duplicate]

You can use INFORMATION_SCHEMA.TABLES to retrieve information about your database tables. As mentioned in the Microsoft Tables Documentation: INFORMATION_SCHEMA.TABLES returns one row for each table in the current database for which the current user has permissions. The following query, therefore, will return the number of tables in the specified database: USE MyDatabase SELECT COUNT(*) FROM … Read more

Is there any reason to worry about the column order in a table?

Column order had a big performance impact on some of the databases I’ve tuned, spanning Sql Server, Oracle, and MySQL. This post has good rules of thumb: Primary key columns first Foreign key columns next. Frequently searched columns next Frequently updated columns later Nullable columns last. Least used nullable columns after more frequently used nullable … Read more

Why use multiple columns as primary keys (composite primary key)

Your understanding is correct. You would do this in many cases. One example is in a relationship like OrderHeader and OrderDetail. The PK in OrderHeader might be OrderNumber. The PK in OrderDetail might be OrderNumber AND LineNumber. If it was either of those two, it would not be unique, but the combination of the two … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)