Contact Us

Use the form on the right to contact us.

You can edit the text in this area, and change where the contact form on the right submits to, by entering edit mode using the modes on the bottom right. 


Oak Ridge, TN, 37830
United States

Sql-Sangria

Table CRUDs

Wade Cantley

Under the Table

  • 2 ounces Licor 43
  • 3 ounces tequila
  • 1 tablespoon fresh lemon juice
  • 3 tablespoons fresh orange juice
  • Dash bitters

Just a straight forward create table template.

CREATE TABLE sample.dbo.test_table
(col1 int NOT NULL,
col2 char(25),
col3 decimal(10,2),
col4 varchar(25),
col5 datetime,
PRIMARY KEY (col1),
UNIQUE (col2))

Update from one table to another

update t1
set col2 = t2.col2
from table1 t1
inner join table2 t2
on t1.col1=t1.col2
where Col3 >5

Delete using a join.

DELETE FROM MyTable1
WHERE EXISTS
(SELECT *
FROM MyTable2
WHERE MyTable2.keyColumn = MyTable1.keyColumn);

Copy from a table in one database to a new table.

SELECT *
INTO new_table_name [IN externaldatabase]
FROM old_tablename

Lets say you want to replace "bob" with "Bob", you would do this.
"bob" would be what you want to search for and replace 'a'
and "Bob" is want you want to put in. 'b'

Here is how you would do it.

UPDATE YourTable
SET Column1 = REPLACE(Column1,'a','b')
WHERE Column1 LIKE '%a%'

Delete duplicate records.

UPDATE YourTable
SET Column1 = REPLACE(Column1,'a','b')
WHERE Column1 LIKE '%a%'

Or maybe you just want to find where there are duplicates, or filter out the unique records.

-- Find all records with only one occurence.
SELECT email
FROM users
GROUP BY email
HAVING ( COUNT(email) = 1 )

-- Search for records with more than one occurance
SELECT email,
 COUNT(email) AS NumOccurrences
FROM users
GROUP BY email
HAVING ( COUNT(email) > 1 )