Create table

2 snippets across 2 stacks — HTML & CSS, SQL

HCHTML & CSS

Basic Table

HC · Lists & Tables
syntax
<table>
  <thead>
    <tr><th>Header</th></tr>
  </thead>
  <tbody>
    <tr><td>Data</td></tr>
  </tbody>
</table>
example
<table>
  <thead>
    <tr>
      <th>Product</th>
      <th>Price</th>
      <th>Stock</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Keyboard</td>
      <td>$89</td>
      <td>142</td>
    </tr>
    <tr>
      <td>Mouse</td>
      <td>$45</td>
      <td>308</td>
    </tr>
  </tbody>
</table>

Note Always use thead/tbody for proper structure. Use th for header cells and td for data cells. This helps screen readers navigate the table correctly.

SQLSQL

CREATE TABLE

SQL · Table Operations
syntax
CREATE TABLE table_name (
  column_name data_type constraints,
  ...
);
example
CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  first_name VARCHAR(100) NOT NULL,
  email VARCHAR(255) NOT NULL UNIQUE,
  is_active BOOLEAN DEFAULT true,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
output
-- Table created with auto-increment ID, constraints, and defaults

Note SERIAL is PostgreSQL-specific (auto-increment integer). MySQL uses INT AUTO_INCREMENT. Standard SQL uses GENERATED ALWAYS AS IDENTITY. Always define a primary key.