The party and ward ids on their own don't tell us much, but as they are foreign keys we can use them to join on the tables that do contain this information: SELECT * FROM Candidate | 1 | Patrick Dorian Hulme | 1 | 1 | 16 | This command shows you all entries in the Candidate table: SELECT * FROM Candidate So the party column is a foreign key pointing at the id column in the Party table. From here we can read off the details of the foreign keys: CONSTRAINT `Candidate_ibfk_1` FOREIGN KEY (`party`) REFERENCES `Party` (`id`)ĬONSTRAINT `Candidate_ibfk_2` FOREIGN KEY (`ward`) REFERENCES `Ward` (`id`) The output is a bit messy but it shows you (more or less) the statement used to create the table. The Key column tells us that id is the primary key (PRI), name has a unique constraint (UNI), party and ward are foreign keys (MUL) and there are no key constraints at all on votes.įor even more information, try this: SHOW CREATE TABLE Candidate The third column (Null) tells you if NULL values are allowed in this column. The first two columns tell you the names and types of columns in this table. | name | varchar(100) | NO | UNI | NULL | | | id | int(11) | NO | PRI | NULL | auto_increment | | Field | Type | Null | Key | Default | Extra | The output will look like this: +-+-+-+-+-+-+ Let's have a look at one: DESCRIBE Candidate You should see Candidate, Party and Ward. Have a look at the tables in this database with SHOW TABLES like elections however are case-sensitive. SQL keywords like USE are not case-sensitive, but it is convention to write them in all upper case. You should see four databases including census and elections. Like all SQL commands, it needs a semicolon at the end. Have a look at the databases that exist with the command SHOW DATABASES Assuming you have installed the database correctly as in the previous activity, you should see the prompt MariaDB > which shows that you are connected to a database server but you have not selected a database yet.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |