I have table and I have tried to remove comments but it gives me a blank comment still.
I have used
ALTER TABLE `b2b`.`mailsysy`
COMMENT = '' ;
to remove existing comment but it puts blak as comment so what to do if I want to remove all comment put only one comment on it.
EDIT
I have tried this also :
If you don't want to retrieve empty comments, then skip them in your query:
SELECT table_comment
FROM information_schema.tables
WHERE table_name ='xxx'
AND TABLE_COMMENT IS NOT NULL
AND TABLE_COMMENT <> ''
demo --> http://www.sqlfiddle.com/#!2/8664d/2
The column TABLE_COMMENT in TABLES and COLUMN_COMMENT in COLUMNS are part of those tables. They are not separated into any child tables. Due to the reason, though you set comments to be empty, the select query returns a row.
The other point you are ignoring is, you are selecting only a column from the TABLES table and omitting other columns though have a record satisfying your where condition. If the where condition is not satisfied, the query would have resulted Empty set (0.00 sec). In your case query resulted 3 rows on other data, that have comments set to empty. And hence you see 3 rows in set (0.01 sec).
I think you are expecting that if a comment is not defined, query should have not fetched a row from the table. If that was the requirements, please note that there is no such child table TABLE_COMMENTS or COLUMN_COMMENTS, which if defined correctly might have had a parent-child relation on TABLES and COLUMNS respectively. And on creation of a table unless you defined a comment it would have not inserted into the respective comments table. And when you query on TABLE_COMMENTS or COLUMN_COMMENTS table, it would have fetched Empty set... satisfying your where condition.
Related
Let's say I have a table with 10 columns, and I have 1 row too.
I want to update only one row and not the others
If I update just one, the other ones will have the default value which is the expected behavior
Is there a way so that I change only a row and still have all the other rows preserve the old values?
I don't want to use a lot of resources for this thing so I wish there's something built-in or something
TL;DR:- How can I update a row and have the other rows stay the same?
I'm using MySQL
An update statement lets you control both the rows being updated and the columns. Usually the rows are defined by the where clause and the columns by the set:
update t
set col4 = <some value>
where col1 = <some value>;
If the where clause is using the table's primary key with an equality condition, then only one row is updated, and only the specified columns in that row change.
IF EXISTS (SELECT * FROM X )
UPDATE [Table] SET...
ELSE
INSERT INTO [Table]
I need assistance trying to find a problem where 1 record/row was updated but the entire table got updated with the same value. Need to understand how this could have happened and implement a method to prevent it from doing so again.
update TABLE set pushID='1234567890' where userID='111222333' ;
What would that update statement do if the userID value equaled nothing or equaled NULL? Could that cause the update statement to update every single row with the same pushID?
IE: update TABLE set pushID='1234567890' where userID='' ;
Could a blank userID value cause this? If not, what could cause this? If so, how could I write the query statement to prevent this from happening again?
What would that update statement do if the userID value equaled nothing or equaled NULL?
If the userID is NULL, then the condition becomes userID = NULL. This will always evaluate as false. In other words, no record will be updated.
If the userID is the empty string, then the condition becomes userID = ''. This will only update records where userID is equal to the empty string. I would expect that userID is the primary key of your table, so it would be suprising the find an empty value. And even if there is one, it will be unique, so a unique record will be updated.
As you see, none of the two above use case would generate a massive update of the table. The most probable option is that the query was triggered without an actual WHERE clause, like:
update TABLE set pushID='1234567890'
In case these are altogether integer ID, you should not convert them to string with ''. Doing so may lead to unexpected results (never tried, but it seems to be a possible cause for the comparison in the WHERE condition to fail). For example:
UPDATE TABLE SET pushID=1234567890 WHERE userID=111222333;
When all records are being updated, the query lacks the WHERE condition. Make sure to have posted the correct query, because this query should update nothing when the WHERE condition fails to match.
I am working on a project in which a table has lot of records. most of the rows have 0 or empty record in column. Its not possible to update all manually or by writing query for each row or column.
Is there efficient way by which i can replace 0's by empty or empty by 0's and one more things..
Some columns have ",0" and "0," which also have to be replaced. here is screenshot of data in screenshot to give idea.. http://prntscr.com/8rvn67
Unfortunately, I can't access the screenshot. Howver, the general solution could be to list the values to be replaced in an IN() clause, if the list is small
update table set fieldname='0' where fieldname in ('',',0','0,")
To remove those 0,,0 to empty space '' you need to use next query
UPDATE table_name
SET column = REPLACE(column, '0', '')
WHERE column LIKE '%0%'
Hope it helps
I have an ecommerce store that I am currently working on and there are approx 300 products which have a field named "product_url"
These fields contains an old url that I need to delete altogether.
How can I create a query that will replace all "product_url" fields with data in them witha null value?
This will set every product_url to NULL which is currently not null.
UPDATE table_name
SET product_url = NULL
WHERE product_url is not null;
First of all, if you have 300 tables (one for each product), you cannot write one query that will set product URLs to NULL.
You have to write a query for each table (UPDATE table_name SET product_url = NULL as others have already said).
And if you have 10,000 products one day, you will have 10,000 tables if you continue like this. This will become a maintenance nightmare since you can see now what kind of problems you have with 300 tables.
Your database is denormalised. If your products share the same attributes, then they should be in one table named "Products", and every product should be represented as one row. Only then can you do what you wanted with one query.
Do you have a table for each product? If so I don't know.
Otherwise;
UPDATE products_table
SET product_url=null
Just an interpration...
UPDATE table_name SET column_name = NULL WHERE column_name = 'product_url'
Assuming ALL entries are to be filled with NULLs:
UPDATE table_name SET product_url = NULL
If you have lots of tables with the same prefix and the same structure, you could do a SHOW TABLES LIKE prefix_%. Then loop through the result set of this query and run separate queries to each table.
This will delete all data in that column without deleting the column itself .
UPDATE `table_name` SET `column_name`=null
So I have a table of data that is 10,000 lines long. Several of the columns in the table simply describe information about one of the columns, meaning, that only one column has the content, and the rest of the columns describe the location of the content (its for a book). Right now, only 6,000 of the 10,000 rows' content column is filled with its content. Rows 6-10,000's content column simply says null.
I have another table in the db that has the content for rows 6,000-10,000, with the correct corresponding primary key which would (seemingly) make it easy to update the 10,000 row table.
I have been trying an update query such as the following:
UPDATE table(10,000)
SET content_column = (SELECT content FROM table(6,000-10,000) WHERE table(10,000).id = table(6-10,000.id)
Which kind of works, the only problem is that it pulls in the data from the second table just fine, but it replaces the existing content column with null. So rows 1-6,000's content column become null, and rows 6-10,000's content column have the correct values...Pretty strange I thought anyway.
Does anybody have any thoughts about where I am going wrong? If you could show me a better sql query, I would appreciate it! Thanks
The reason is that you have no Where clause so all rows are being updated. The following query will only update tows that exist in the 6K-10K table, but will still overwrite matching values.
Update table(10,000)
Set content_column = (
Select content
From table(6,000-10,000)
Where table(10,000).id = table(6-10,000.id)
)
Where Exists (
Select 1
From table(6,000-10,000)
Where table(10,000).id = table(6-10,000.id)
)
Another way, if you simply do not want to overwrite the existing values would be to use Coalesce:
Update table(10,000)
Set content_column = Coalesce(table(10,000).content_column
, (
Select content
From table(6,000-10,000)
Where table(10,000).id = table(6-10,000.id)
))