码迷,mamicode.com
首页 > 其他好文 > 详细

Working with Data Sources 8

时间:2016-11-22 07:42:26      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:ima   add   type   ati   main   sel   als   alt   query   

Data Schema is the table which contains all the data types of another table.

1. Add column in schema table for the main table by using ALTER TABLE... ADD

  ALTER TABLE facts

  ADD awesomeness integer; # have to mention datatype

2. Delete column from schema table by using ALTER TABLE... DROP COLUMN...

  ALTER TABLE facts DROP COLUMN awesomeness;

3. Create table by using CREATE TABLE statement:

  CREATE TABLE factbook.leaders(

  id integer PRIMARY KEY,

  name text,

  country text);

4. Relations between TABLES:

  CREATE TABLE factbook.leaders(

  id integer PRIMARY KEY,

  name text,

  country integer, #have to create country column before it is associated to a foreign column

  worth float,

  FOREIGN KEY(country) REFERENCES facts(id) # set a foreign column which is come from another column # The value country column comes from a foreign column

  );

5. Also,we can use INNER JOIN to make querying across foreign relationsships, create a table that combines both column and values according to their common(related) column:

  SELECT * from states

  INNER JOIN facts

  ON states.country == facts.id; 

 

6. Also,beside INNER JOIN there are LEFT JOIN and RIGHT JOIN:

  select * from landmarks left outer join facts on facts.id == landmarks.country

 

Working with Data Sources 8

标签:ima   add   type   ati   main   sel   als   alt   query   

原文地址:http://www.cnblogs.com/kingoscar/p/6087734.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!