Adding Data to a Database Table Carol Wolf Computer Science.

Slides:



Advertisements
Similar presentations
How To Make Your Own Web Page: Basic Web Design
Advertisements

The Librarian Web Page Carol Wolf CS396X. Create new controller  To create a new controller that can manage more than just books, type ruby script/generate.
Comp 335 File Structures Indexes. The Search for Information When searching for information, the information desired is usually associated with a key.
Quick-and-dirty.  Commands end in a semi-colon ◦ If you forget, another prompt line shows up  Either continue the command or…  End it with a semi-colon.
CS 142 Lecture Notes: Rails ActiveRecordSlide 1 Model for Student Table SELECT * FROM students; | id | name.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley A Case Study in Database Organization The iDiary Database lawrence snyder.
Creating a wiki blog. Run apps that come with instant rails distribution select I /rails applications/open ruby console window Cd to cookbook or typo.
Ruby on Rails Creating a Rails Application Carol E Wolf CS396X.
Textbook Management and the Insignia Library System.
Ruby on Rails: An Introduction JA-SIG Summer Conference 2007 Michael Irion The University of Tulsa.
MGMS Databases Cool, reliable resources just a few clicks away!
The Ruby Programming Language
Web of Science. Copyright 2006 Thomson Corporation 2 Example: (bird* or avian) and (flu or influenz*) Enter your terms to be searched. Search fields are.
1 Dr Alexiei Dingli Web Science Stream Models, Views and Controllers.
Xin  Syntax ◦ SELECT field1 AS title1, field2 AS title2,... ◦ FROM table1, table2 ◦ WHERE conditions  Make a query that returns all records.
DAY 15: ACCESS CHAPTER 2 Larry Reaves October 7,
Database Basics   Describe the basic organization of a database.   Summarize advantage to using database software.   Define GIGO, and explain how.
Using someone else’s words as your own by: ≈ Directly copying from a book or other work ≈ “Cut and paste” from the Internet Use “quotation marks” around.
Ruby on Rails Your first app. Rails files app/ Contains the controllers, models, views and assets for your application. You’ll focus on this folder for.
Copyright © Eric Liria Web Site Builder This application allows you to build and manage web sites. It provides the following functionnalities: use.
OPAC Training aid (Library solutions & Library world)
Research Papers: Footnotes, Citations, and Bibliographies.
Research Project Career Exploration Portfolio. Project Information Topic: Career that interests you Must be specific (anesthesiologist, not doctor) Must.
Ruby on Rails CSE 190M, Spring 2009 Week 6. Overview How to use a database Demo creating a blog application on Rails Explain how the application works.
More about Databases. Data Entry through Forms Table View (Data sheet view) is useful for data entry of new records But sometimes customization would.
The online catalog defaults to the Power Search screen.
Associations INFO 2310: Topics in Web Design and Programming.
Photo Gallery INFO 2310: Topics in Web Design and Programming.
CS 142 Lecture Notes: Rails ActiveRecordSlide 1 Model for Student Table SELECT * FROM students; | id | name.
Ruby on Rails: Databases. Rails Database Familiar Table Concept Naming convention – lower case, plural (i.e. tweets) How to Access (find), Update, Delete.
Computers in the Library A database application. Input and Output Devices Input Keyboard Mouse Scanner / light pen Output VDU / screen / monitor Printer.
When I want to work with SQL, I start off as if I am doing a regular query.
Testing Carol Wolf Computer Science. Testing built into Rails  Rails comes with three databases.  development  test  production  The test database.
UDL Book Builder for Teachers Image sources: Cast UDL.
3 Data. Software And Data Data Data element – a single, meaningful unit of data. Name Social Security Number Data structure – a set of related data elements.
1 Migration. 2 What’s Migration? Migration –Isolates database differences Allows you to write schema updates without worries about differences –Helps.
Hannah Hawlk MEDT 7478 Fall 2012 From the opening menu, click on the “catalog” tab to open the catalog module.
Create, Update and Delete Carol Wolf Computer Science.
Lecture 13b Rails – Controllers and Views Topics SaaSSaaS Readings: SaaS book Ch March 3, 2014 CSCE 740 Software Engineering.
MySQL Getting Started BCIS 3680 Enterprise Programming.
Introduction to Ruby&Rails Yuri Veremeyenko Monica Verma.
Microsoft Access 2000 Creating Queries, Reports and Web Pages.
Microsoft Access Introduction. What is a database? A DATABASE is a collection of related data.
CS 160 and CMPE/SE 131 Software Engineering February 9 Class Meeting Department of Computer Science Department of Computer Engineering San José State University.
A am going to create a table in design view. I am going to create a table in an Access database that contains information about the books that I have on.
Introduction to information systems RUBY ON RAILS dr inż. Tomasz Pieciukiewicz.
The Controller Carol Wolf Computer Science. Rails generate commands  Using the generate command, you can create a number of useful objects.  Rails:
Migrations Carol Wolf CS 396X. ISBNTitleAuthorImage EmmaAustenemma.jpg Oliver TwistDickenstwist.jpg HamletShakespearehamlet.jpg.
Creating a database - I clicked on blank database and am saving it as books10.mdb. For more information see the practice example under week #1. I am going.
Adding Reports to a Database. Why do we use Reports? Reports are well-designed printed pages that offer several advantages: Reports are well-designed.
Web based Documentation Distribution Tools: MSAccess database (DSN) DreamWeaver Ultradev Microsoft Image Composer Clicking on the document will open an.
Advanced Migration By Aye Mon Tun.  To change database schema in consistent and easy way  In ruby code Migration? 11/25/2013 2Web Application Engineering.
MySQL Getting Started BCIS 3680 Enterprise Programming.
Microsoft® Access Generate reports quickly 1 Modify controls in layout view 2 Work with report sections 3 Work with controls in a report 4 Use Format.
Connecting From Home Editing at Home(You don’t have to.)
Database Applications – Microsoft Access Lesson 5 Shared Data.
Intro to WordPress (Using XAMPP)
Query Methods Simple SQL Statements Start ….
Dept. of Computer & Information Sciences
Permissions to database objects Indexes RUNSQLSTM Referential Constraint options ON DELETE RESTRICT ON DELETE CASCADE ON DELETE SET DEFAULT Lab.
Database application MySQL Database and PhpMyAdmin
Hierarchy of Data in a Database
Agile Web Development with Ruby and Rails
Painted Shadows - Not Allowed
RDFinancial in PowerPoint
Permissions to database objects Indexes RUNSQLSTM Referential Constraint options ON DELETE RESTRICT ON DELETE CASCADE ON DELETE SET DEFAULT Lab.
Why We Need Car Parking Systems - Wohr Parking Systems
Types of Stack Parking Systems Offered by Wohr Parking Systems
Add Title.
Presentation transcript:

Adding Data to a Database Table Carol Wolf Computer Science

Adding data to a books table  Create a books table using rails generate scaffold book isbn:string author:string title:string  We can add data to the table using the New Book link at the bottom of the index page.  This is slow and for tables with a large number of fields very cumbersome.  Instead a lot of data can be added at once using either a migration or modifying seeds.rb in the db folder.

Using a migration  Create a migration using rails generate migration add_data  This produces class AddData < ActiveRecord::Migration def self.up end def self.down end  Add data to get the following:

class AddData < ActiveRecord::Migration def self.up Book.create( :isbn => ' ', :author => 'Chekov', :title => 'The Cherry Orchard' ) Book.create( :isbn => ‘ ’, :author => ‘Hemmingway’, :title => ‘The Sun Also Rises’ ) … end def self.down Book.delete_all end

Modifying seeds.rb  seeds.rb is in the db folder.  It is generated along with everything else when a new rails project is created. # This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). # # Examples: # # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) # Mayor.create(:name => 'Daley', :city => cities.first)  You can add data to it using the form indicated.  It is run using rake db:seed. (Note: no plural)

# This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). # # Examples: # # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) # Mayor.create(:name => 'Daley', :city => cities.first) books = Book.create([ {:isbn => ' ', :author => 'Chekov', :title => 'The Cherry Orchard'}, {:isbn => ' ', :author => 'Hemmingway', :title => 'The Sun Also Rises'}, {:isbn => ' ', :author => 'Steinbeck', :title => 'The Grapes of Wrath'} ])  Note the curly braces around the hashes and the square brackets around all the data.  This is shorter than the migration and easier to do. But they both work.