Most Popular

1500 questions
22
votes
2 answers

Update table using values from another table in SQL Server

I have 2 table in my database. Table #1 ------------------------------------------------------------------------- | name | family | phone | email | gender | phone2 | address | birthdate…
John Doe
  • 351
  • 2
  • 3
  • 6
22
votes
4 answers

Best design to reference multiple tables from single column?

Proposed schema First and foremost, here is an example of my proposed schema to reference throughout my post: Clothes ---------- ClothesID (PK) INT NOT NULL Name VARCHAR(50) NOT NULL Color VARCHAR(50) NOT NULL Price DECIMAL(5,2) NOT NULL BrandID…
youngrrrr
  • 323
  • 1
  • 2
  • 6
22
votes
4 answers

How can I drop all triggers in a single database?

I have a database with 104 triggers, is there a way to delete all the triggers with a single command from a single database called 'system_db_audits?
Mohamed Mahyoub
  • 363
  • 1
  • 2
  • 7
22
votes
2 answers

Is it possible to force the optimizer to eliminate irrelevant tables in this partitioned view?

I'm testing different architectures for large tables and one suggestion that I've seen is to use a partitioned view, whereby a large table is broken into a series of smaller, "partitioned" tables. 1, 2, 3, 4 In testing this approach, I've discovered…
swasheck
  • 10,665
  • 4
  • 47
  • 88
22
votes
1 answer

Meaning of 'locks rec but not gap waiting' in deadlock report

About the meaning of locks rec but not gap waitingin TRANSACTION(1), which one is correct? Already granted gap lock, waiting for clustered index X lock? Already granted clustered index X lock, waiting for gap lock? There are 31 rows in…
Ryan Lyu
  • 513
  • 2
  • 4
  • 13
22
votes
2 answers

Does an empty column value occupy same storage space as a filled column value?

I have a table with 2 columns. The type of both columns is set to varchar(38). If I create a row with an empty value for one of the columns, will it take same storage space as if the value was not empty? In other words, will MySQL reserve storage…
Haris ur Rehman
  • 353
  • 1
  • 3
  • 7
22
votes
2 answers

PostgreSQL - Who or what is the "PUBLIC" role?

I was looking at information_schema.role_table_grants when I saw public in grantee column, then I've checked at information_schema.enabled_roles but this role_name does not exist. => Who or what is the public role?
gokan
  • 323
  • 1
  • 2
  • 4
22
votes
1 answer

Use of log_bin_trust_function_creators in MySQL

What is the use of log_bin_trust_function_creators? Also, Is the value of the parameter dynamic? Will it change if I restart my MySQL service?
tesla747
  • 1,896
  • 10
  • 39
  • 74
22
votes
2 answers

Locking in Postgres for UPDATE / INSERT combination

I have two tables. One is a log table; another contains, essentially, coupon codes that can only be used once. The user needs to be able to redeem a coupon, which will insert a row into the log table and mark the coupon as used (by updating the used…
Rob Miller
  • 323
  • 1
  • 2
  • 6
21
votes
1 answer

postgresql rename a foreignkey after renaming a table

I renamed a table, and apparently a foreignkey in it doesn't get changed, and causing problems, Although when I \d error I get: "error_test_id_fkey" FOREIGN KEY (test_id) REFERENCES test(id) ON DELETE CASCADE Which the only relation to error name,…
Boaz
  • 313
  • 1
  • 2
  • 4
21
votes
2 answers

Select all records, join with table A if join exists, table B if not

So here's my scenario: I'm working on Localization for a project of mine, and typically I would go about doing this in the C# code, however I want to do this in SQL a bit more since I am trying to buff up my SQL a bit. Environment: SQL Server 2014…
Der Kommissar
  • 1,513
  • 1
  • 15
  • 27
21
votes
1 answer

In a MySQL Master/Slave replication, what would happen if I write to the Slave?

Several Questions Would the Slave entry remain until there is an insert/update/delete to the table on the Master that could affect the Slave? If not, how do I ensure that the Slave is in-sync with the Master going forward (either by deleting the…
kfmfe04
  • 849
  • 2
  • 8
  • 12
21
votes
2 answers

Difference between GROUP BY B,A and GROUP BY COALESCE(B,A)

I have been getting myself very confused. Could somebody kindly explain under what circumstances I would want to use a GROUP BY COALESCE? My guess is that I would use it if I wanted to conditionally group a set of data by column B (if B was not…
Mark McLaren
  • 323
  • 4
  • 13
21
votes
7 answers

Get last full backup and transaction log backup for each database

How to write script or a query that will display the last full backup and the last log backup for each database on each of the production servers using the system table "backupset" and related backup tables.
Janice
  • 315
  • 1
  • 3
  • 4
21
votes
4 answers

What is the Query to display the failed sql jobs

What is the Query to display the failed sql jobs,so that I can get all the failed job information with one query
Avi
  • 327
  • 1
  • 3
  • 6