Take a fresh look at your lifestyle.

Các câu lệnh truy vấn trong sql server 2008

185
Rate this post

Các câu lệnh truy vấn trong sql server 2008 mà lập trình viên nào cũng phải biết

1. SELECT:

SELECT * FROM table;

2. WHERE:

SELECT age, name FROM people WHERE age > 10;

3. ORDER:

SELECT name, age FROM people ORDER BY age DESC;

4. JOIN:

SELECT age, name, height FROM people LEFT JOIN heights USING (name);

5. ALIAS:

SELECT A.age FROM people A;

6. UNION:

SELECT age, name FROM customers
UNION 
SELECT age, name FROM staff;

7. INSERT:

INSERT INTO people(name, age) VALUES('Joe', 102);

8. UPDATE:

UPDATE people SET name = ‘Joe’, age = 101;

9.UPSERT:

INSERT INTO people(name, age)
VALUES('Joe', 101)
ON DUPLICATE KEY UPDATE age = 101;

10. DELETE:

DELETE FROM people;

11. CREATE TABLE:

CREATE TABLE people (
  name TEXT,
  age, INTEGER,
  PRIMARY KEY(name)
);

12. ALTER TABLE:

ALTER TABLE people ADD height integer;

13. DROP TABLE:

DROP TABLE people;
Bạn cũng có thể thích