Update column title in databse in SQL Server - ssms-2012

I'd like to update the title of column in a database that I created in SSMS 2012.
I've seen some examples where records in the table are updated, but not the actual column titles.
The column title had a typo so all I want to do is change 'deparment' to department (with a 't' in the middle).
The database is called department.
I believe I'd need to do something along the lines of
Update department (ie the database I'm updating) then
Set?
Can someone please clarify what the rest of the query should look like?
Thanks in advance.

Related

I want to add two columns in MySql workbench?

My table name is 'bills' i want the sum of columns Electricity and gas and their sum should automatically stored in the column named as Total.Which trigger can do this work please tell me its correct code.I have searched a lot but didn't got my answer.
Electricity+Gas=Total
1 2 3
Sorry, if HerrSekurr is correct and this is homework, it's a trick question.
Tell your teacher: "Teacher, one should never store a derived result back into a table. The beauty and power in SQL is the ability to generate the desired query with the CURRENT data."
To do so: "select electricity, gas, sum(electricity + gas) from your_table"
Now, if you want an index (maybe that's the database term you really meant), accept my answer, then ask a new question...

Is it possible to check if any of the field in a mysql row is empty?

Ran into a brick wall & I came running here for help.
Is it possible to check if a field is empty in a given mysql table row and no, I do not want to check by each column name ( with a single line sql if possible).
I would elaborate some more:
say if I have a table with columns t1_col1,t1_col2 and ...
so I would like to know if any of these columns is empty.
and if I have another table with columns t2_col1, t2_col2 and ..
I would like to use the SAME sql statement to check if any of these columns are empty.
I have not tried anything, because I do not know what to try, I know it is possible to achieve this by checking if column are null ( if column names are known that is and also I know column names of table can be found by 'show column' of mysql). So those are not the way I want to go. I want to know if there is any single command that can do this checking ?
Can any body help me please.
There is no such thing in MySQL. You will have to check each column.
However, it is possible to get the table schema like this:
DESCRIBE table_name;
It will give you a list of all columns in the table, then using your favorite programming language, you can cycle over all fields to create a query to check if they are empty.

Create columns that autoincrement with name in a MySQL Database

I know that this might seem like a strange question, but let me try and explain it. I have a database table called 'plan' and in it the first column is called 'username' and the columns after it are called 'question1', 'question2' and so on. I now need to add a hundred or so more columns named like this, but it would be nice to have a sql statement that would automatically do that for me.
I know this wasn't set up in the best way, but if you have a solution, please let me know :)
There isn't any SQL command or feature that would do this automatically; sure you can generate the alter table statements and add the columns programmatically; however, your design would be terribly flawed.
Instead of adding columns, you should create a table containing the question, the user_id (or username, whatever is the PK) to hold the records. If you need to identify a question by number (or ID), simply add another column called question_id.
Write the query in sql to excel. Seperate the incrementing number. Drag down until excel row 100. Hard to explain but i guess you ll figure it out. You'll have 100 incrementing add column sql statements. copy paste run it on a query tool.

how can I add records through a query in access?

Before I remade this simple database, I was able to perform a query and update and insert new records from that query. I can no longer do this and can't figure out why.
I'm not very knowledgeable with access so any help would be greatly appreciated. I have a feeling that this may have something to do with the auto number column that no longer exists. Basically, it wouldn't allow me to change the data type after I had entered data into the table. I needed to do this to preserve the primary key as they match the client's records and cannot be changed.
If I understand you right you have a query that used to work (and insert records in a table) and now doewsn't work anymore? Can you post the SQL of the query and the structure of the table that you are inserting in? That will make it a lot easier for the rest of the world to help you.

MySQL table design

I have a table with products. Each product has a title and a price.
The products come in huge XML files, on a daily basis.
I store all of them in MySQL. But sometimes they have a wrong title. But i can't edit it, because they will be lost the next day (cronjob removes all products and inserts again).
What would be the best way to edit them? Save them in a different table and SELECT both tables at once? Whereas the table that contains the edited rows has precedence over the cronjob table.
What would be the best way to handle it, since there are 300.000+ products. Products might be (manually) edited via a CMS system.
Thanks!
Is there some sort of ID that remains constant? (productID) for example?
Can you edit the cronjob?
If both of the above is true; i'd edit the job to only add new records into the table; preventing writing over your updated values.
If there is a unique identifier for each product that remains constant over updates, you could make a table containing the product ID and the corrected title. Correcting a title would involve inserting a row into this table as well as updating the main table.
As the last step of the cron job, you can then update your main table of products from this one.
UPDATE FROM tblProduct p, tblProductCorrections pc
SET p.strTitle = pc.strCorrectedTitle
WHERE p.intId = pc.intProductId