tags:

views:

286

answers:

2

What would be the syntax (if it's possible), for example, to create a table called Car_Model that has a foreign key to a table Car_Make, and give Car_Make a column which is the number of Car_Models that exist of that Car_Make.

(If this seems trivial or homework-like it's because I am just playing with some python at home trying to recreate a problem I was having at work. We use MS-SQL at work.)

+1  A: 

I think the Firefox SQLite Manager is what you need. I use it all the time when I need a testdb.

From webpage:

Long Description

Manage any SQLite database on your computer. An intuitive heirarchical tree showing database objects. Helpful dialogs to manage tables, indexes, views and triggers. You can browse and search the tables, as well as add, edit, delete and duplicate the records. Facility to execute any sql query. The views can be searched too. A dropdown menu helps with the sql syntax thus making writing sql easier. Easy access to common operations through menu, toolbars, buttons and context-menu. Export tables/views/database in csv/xml/sql format. Import from csv/xml/sql (both UTF-8 and UTF-16). Possible to execute multiple sql statements in Execute tab. You can save the queries. Support for ADS on Windows.

Nifle
+2  A: 

SQLite doesn't supported computed columns.

However your problem can be solved with a relatively simple SQL Query, you can then create a view to make it appear like a table with the extra computed columns.

SELECT Car_Make.Name, Count(*) AS Count FROM Car_Make, Car_Model WHERE Car_Make.Id = Car_Model.Make GROUP BY Car_Make.Name

This should return a table similar to the following

Name      Count
----      -----
Nissan    5
Toyota    20
Ford      10
Diaa Sami