2010. 3. 12. 11:06

SQL 명령어 구문들 (Statements)

use test

CREATE TABLE userinfo (
number  int,
name  char(10),
id  char(8),
password char(10),
age  int,
birthday  char(10),
sex  char(1),
daytype  char(1),
zip  char(7),
address  varchar(50),
phone  char(15),
company varchar(50),
comaddr varchar(100),
comphone char(15),
handphone char(15),
pager  char(15),
fax  char(15),
email  varchar(40),
compos  varchar(20),
partcode char(10),
introduce text
)

SELECT * FROM userinfo

SELECT id, name, address, phone FROM userinfo

SELECT * FROM userinf WHERE age >= 25

SELECT DISTINCT name FROM userinfo

SELECT name AS fullname FROM userinfo

SELECT * FROM userinfo WHERE name LIKE '김%' OR (sex = 'm' AND age >= 25)

SELECT * FROM userinfo ORDER BY name DESC
SELECT top 10 * FROM userinfo ORDER BY age DESC SELECT avg(age) as ageAvg FROM userinfo GROUP BY partcode SELECT AVG(age) AS ageAvg FROM userinfo GROUP BY partcode HAVING ageAvg >= 33 CREATE TABLE userlog (
id char(8),
login int,
userip char(15)
)

INSERT INTO userlog VALUES('tiger', 30, '203.220.22.10')

INSERT INTO userlog(id, login) VALUES('star', 20)

SELECT * FROM userlog

DELETE userlog WHERE login < 30

begin tran
UPDATE userlog SET login = 25, userip = '203.220.22.20' WHERE id = 'tiger'
rollback tran