learn-co-curriculum / sql-table-relations-readme Goto Github PK
View Code? Open in Web Editor NEWLicense: Other
License: Other
Step 2: Creating the Owners Table
First, we need to create our owners table. An owner should have an ID that is a primary key integer and a name that is text:
CREATE TABLE owners (id INTEGER PRIMARY KEY, name TEXT);
Now that we have our owners table, we can add a foreign key column to the pets table.
Error: Last sentence should read "foreign key column to the cats table".
The tables that were created were cats and owners. There is no 'pets table' for this example.
Hi this should read "tables" not "rows".
I'd written out diagrams over and over and over and couldn't figure out how 'rows' for Author and Post would be plausible.
Line # 7 : change 'rows" to "tables" . "figure out how to related two rows ( a Post and an Author) using only...."
*********Relating Tables with Foreign Keys
Continuing the posts and authors examples, you could say that an author has many posts. The reciprocal of this would be that a post belongs to an author. Now we need to figure out how we can represent that relationship within the constraints of SQLite. If you were writing just plain ruby, how would you represent this relationship? In our Author class we would have an array of Post objects. Our Post object would have a single attribute that holds its Author. This is great in Ruby, but there is no data type for arrays in SQL. You can only have INTEGER, FLOAT, and TEXT. So developers had to figure out how to relate two rows (a Post and an Author) using only those data types. Is there any way we can convert an INTEGER into a specific row in a table? OH YEAH.
I dunno with the edits from #5 if you'll need the cd
but it should be all lower case and in backticks
Capitalize Ruby in last line below.
Relating Tables with Foreign Keys
Continuing the posts and authors examples, you could say that an author has many posts. The reciprocal of this would be that a post belongs to an author. Now we need to figure out how we can represent that relationship within the constraints of SQLite. If you were writing just plain ruby, how
This isn't lesson specific, but it occurred to me how helpful it would be if there were a central html file or git repository with all the external resource links organized by topic. I would love to be able to go in a grab them all into bookmarks folders to save for future use, yet I find within the workflow of learn, my focus is on completing lessons and not exploring them as much, so I sometimes skip over them.
Just a thought
MC
Include the starter .db
file in this and remove reference to "previous lab"
Before you jump in, talk about how your goal is to use a new table called owners
that each owner
will have many cats
.
I can't remember if this is the first time they encounter foreign keys. If this, we need to walk them a bit more through this. Don't just explain what. Explain why
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.