How to update two tables in one statement in SQL Server 2005?

You can’t update multiple tables in one statement, however, you can use a transaction to make sure that two UPDATE statements are treated atomically. You can also batch them to avoid a round trip. BEGIN TRANSACTION; UPDATE Table1 SET Table1.LastName=”DR. XXXXXX” FROM Table1 T1, Table2 T2 WHERE T1.id = T2.id and T1.id = ‘011008’; UPDATE … Read more

Difference between natural join and inner join

One significant difference between INNER JOIN and NATURAL JOIN is the number of columns returned. Consider: TableA TableB +————+———-+ +——————–+ |Column1 | Column2 | |Column1 | Column3 | +———————–+ +——————–+ | 1 | 2 | | 1 | 3 | +————+———-+ +———+———-+ The INNER JOIN of TableA and TableB on Column1 will return SELECT * … Read more

Changing the maximum length of a varchar column?

You need ALTER TABLE YourTable ALTER COLUMN YourColumn <<new_datatype>> [NULL | NOT NULL] But remember to specify NOT NULL explicitly if desired. ALTER TABLE YourTable ALTER COLUMN YourColumn VARCHAR (500) NOT NULL; If you leave it unspecified as below… ALTER TABLE YourTable ALTER COLUMN YourColumn VARCHAR (500); Then the column will default to allowing nulls … Read more

Turn off constraints temporarily (MS SQL)

— Disable the constraints on a table called tableName: ALTER TABLE tableName NOCHECK CONSTRAINT ALL — Re-enable the constraints on a table called tableName: ALTER TABLE tableName WITH CHECK CHECK CONSTRAINT ALL ——————————————————— — Disable constraints for all tables in the database: EXEC sp_msforeachtable ‘ALTER TABLE ? NOCHECK CONSTRAINT ALL’ — Re-enable constraints for all … Read more

Postgres unique constraint vs index

I had some doubts about this basic but important issue, so I decided to learn by example. Let’s create test table master with two columns, con_id with unique constraint and ind_id indexed by unique index. create table master ( con_id integer unique, ind_id integer ); create unique index master_unique_idx on master (ind_id); Table “public.master” Column … Read more

SQL: IF clause within WHERE clause

Use a CASE statement UPDATE: The previous syntax (as pointed out by a few people) doesn’t work. You can use CASE as follows: WHERE OrderNumber LIKE CASE WHEN IsNumeric(@OrderNumber) = 1 THEN @OrderNumber ELSE ‘%’ + @OrderNumber END Or you can use an IF statement like @N. J. Reed points out.

django test app error – Got an error creating the test database: permission denied to create database

When Django runs the test suite, it creates a new database, in your case test_finance. The postgres user with username django does not have permission to create a database, hence the error message. When you run migrate or syncdb, Django does not try to create the finance database, so you don’t get any errors. You … Read more

SQL WHERE ID IN (id1, id2, …, idn)

Option 1 is the only good solution. Why? Option 2 does the same but you repeat the column name lots of times; additionally the SQL engine doesn’t immediately know that you want to check if the value is one of the values in a fixed list. However, a good SQL engine could optimize it to … Read more

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