MySQL: Show databases and show tables

This entry is part 14 of 26 in the series Learn MySQL

Once you have login to mysql, you can use the help command to display a list of mysql commands.

Notice this line that all commands must end with ; in the screenshot.

sqlcommands

So to show the databases we are currently having, we can use

show databases;

showdatabases

And to display the tables in the databases,

use allartist;
show tables;

showtables

 

MySQL Clients: Creating DB and table

This entry is part 8 of 8 in the series MySQL Clients

Using an earlier example, let’s go ahead and create a database and a table.

We will use the same code illustrated in the example.

CREATE TABLE artist
    (
 id int auto_increment primary key, 
 artiste varchar(30), 
 album varchar(50),
 price decimal(3, 2) 
 );
  
INSERT INTO artist
(artiste, album, price)
VALUES
('Rod Stewart', 'Maggie May', 8.90 ),
('New Order', 'Substance', 7.50),
('Nirvana', 'Smell Like Teen Spirit', 9.80);

First create the database using

create database allartist

console_create

Now we create a table and insert a row into it.

We need to use use allartist to ensure that the table is created under the table allartist.

console_createtable

console_insert

We can use select * from artist to check if the table has the inserted data.

jQuery Selectors: Applying indexed selector to table row

This entry is part 31 of 33 in the series jQuery Selectors

$(‘tr:eq(4)’)

As in the earlier example, the index selector could be applied to selecting a particular row in a table.

<!DOCTYPE html>
<html>
<head lang='en'>
    <meta charset='UTF-8'>
    <title>HTML Table</title>
    <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script>
    <script>
        $(function () {
            $('tr:eq(4)').css('background-color', 'lightgray');
        });
    </script>
</head>
<table border='1'>
    <tr>
        <th>ID</th>
        <th>artiste</th>
        <th>album</th>
        <th>year</th>
    </tr>
    <tr>
        <td>1</td>
        <td>Rod Stewart</td>
        <td>Maggie May</td>
        <td>1973</td>
    </tr>
    <tr>
        <td>2</td>
        <td>New Order</td>
        <td>Substance</td>
        <td>1987</td>
    </tr>
    <tr>
        <td>3</td>
        <td>Nirvana</td>
        <td>Smell Like Teen Spirit</td>
        <td>1992</td>
    </tr>
    <tr>
        <td>4</td>
        <td>Rod Stewart</td>
        <td>Out Of Order</td>
        <td>1988</td>
    </tr>
</table>
</body>
</html>

HTML Table: Formatting all tables and cells the same way

This entry is part 13 of 16 in the series HTML Table

To format all tables and cells the same way, define the attributes in an embedded style sheet.

<!DOCTYPE html>
<html>
<head lang='en'>     
    <meta charset='UTF-8'>
    <title>Codecrawl.com-HTML Table</title>
    <style>
        table {
            border-style: dotted;
            border-color: red;
            border-width: 1px;
        }

        td {
            border-style: dashed;
            border-color: green;
            border-width: 1px
        }

    </style>
</head>
<body>

<table>
    <tr>
        <th>ID</th>
        <th>artiste</th>
        <th>album</th>
    </tr>
    <tr>
        <td>1</td>
        <td>Rod Stewart</td>
        <td>Maggie May</td>
    </tr>
</table>

</body>
</html>

HTML Table: Styling a table

This entry is part 12 of 16 in the series HTML Table

You can apply borders by using CSS which is the most consistent method across browsers.

  • The border-width attribute controls the thickness of the border.  Specify a value in pixels
  • The border-color attribute controls the color of the border. Specify a color by name, hexadeimal number or RGB value.
  • The border style attribute controls the line style.  Choose among solid, dotted, dashed, double, groove, ridge, inset, outset or none.
  • To set all three attriubutes at once, use the border attribute and then place the settings after it in this order: width, color, style
  • To format the border sides individually, replace the border attribute with the border-top, border-bottom, border-left or border-right attribute.
<!DOCTYPE html>
<html>
<head lang='en'>     
    <meta charset='UTF-8'>
    <title>Codecrawl.com-HTML Table</title>
</head>
<body>

<table style='border-style: dotted; border-color: green; border-width: 2px'>
    <tr>
        <th style='border-style: groove; border-color: red; border-width: 2px'>ID</th>
        <th>artiste</th>
        <th>album</th>
    </tr>
    <tr>
        <td>1</td>
        <td>Rod Stewart</td>
        <td>Maggie May</td>
    </tr>
</table>

</body>
</html>
Output: Styling Border Using CSS  
I now make a slight change to the table with width=50% and we could see better how a groove border look like for a table.
 
Output: Groove Border