Sql 기본적인 문법 정리

Sql 기본적인 문법 정리

SELECT, INSERT, UPDATE, DELETE


테이블 생성

1
2
3
4
5
CREATE TABLE student (
	id INTEGER, 
	name TEXT,
	age INTEGER
);

위와 같이 테이블을 생성하면 아래와 같은 스키마가 형성됩니다.

id INTEGER
name TEXT
age INTEGER


삽입

1
2
INSERT INTO student (id, name, age) VALUES (1, 'Jane', 20);
INSERT INTO student (id, name, age) VALUES (2, 'Ami', 21);


조회

1
SELECT * FROM student;
id name age
1 Jane 20
2 Ami 21


변경

1
2
3
4
5
UPDATE student
SET age=22
WHERE id=1;

SELECT * FROM student;
id name age
1 Jane 22
2 Ami 21


colume 추가

1
2
3
4
ALTER TABLE student ADD COLUMN
major TEXT;

SELECT * FROM student;
id name age major
1 Jane 22 NULL
2 Ami 21 NULL


1
2
3
4
5
UPDATE student 
SET major='Computer engineering'
WHERE id=1;

SELECT * FROM student;
id name age major
1 Jane 22 Computer engineering
2 Ami 21 NULL


삭제

1
2
3
DELETE FROM student WHERE major IS NULL;

SELECT * FROM student;
id name age major
1 Jane 22 Computer engineering


comments powered by Disqus