Mats codemix

Mats codemix

A little c#, a litte .NET and throw in some c++ and you get a nice Spaghetti

Mats codemix RSS Feed
 
 
 
 

Posts tagged SQL

Making groups unique - fixing a duplicate key problem in SQL

I ran into a problem where updating a key column caused duplicate key errors.  The table in question had several columns that formed the Primary Key.  One of those columns was userd for a  serial number making groups of keys unique.
Example

Group

GroupSerial

Apple

1

Apple

1

Pear

1

Pear

1

Here we see that each row is not unique.
So how can we fix this?
First [...]

Generate SQL-code with line breaks from metadata

I’m  updating a system with lots of tables and i wanted to perform the same operation on more than 20 of the tables.  Writing all those update statements by hand is errorprone and using copy-paste is equally worse.
I wanted to write good code with linebreaks, logmessages  and comments. What to do?
Code-generation to the rescue!

1 [...]

SQL - Show tables containing a column

When digging through database tables i use this little select-sctatement to find out which tables that contain a scertain column name.
1 — Show tables containing a column
2 select sysobj.name + ‘.’ + syscol.name
3 , ’sp_help ‘ + sysobj.name as sptext
4 , ’select * from ‘ + sysobj.name as selall
5 , [...]