SQL Kernel

SQL (Structured Query Language) is one of the oldest and most popular languages for database access. Beaker has first-class support for SQL, including syntax highlighting, autocompletion, and autotranslation. Most of the languages in Beaker have their own SQL APIs, and you can use them as well.

In order to be completely self-contained, this demo notebook uses an in-memory H2 database, and it’s built from scratch in the first cell. Normally you would connect to an existing database by putting its JDBC configuration in the notebook metadata.

For example, if you want to connect to a MySQL running locally then use: jdbc:mysql://localhost/dbName, where dbName would be replaced as appropriate.

In [1]:
drop table if exists color;
CREATE TABLE color (
  id int(11) NOT NULL,
  name varchar(45) NOT NULL,
  code varchar(10),
  PRIMARY KEY (id)
);

INSERT INTO color (id, name, code) VALUES (1001,'AliceBlue','#F0F8FF');
INSERT INTO color (id, name, code) VALUES (1002,'AntiqueWhite','#FAEBD7');
INSERT INTO color (id, name, code) VALUES (1003,'Aqua','#00FFFF');
INSERT INTO color (id, name, code) VALUES (1004,'Aquamarine','#7FFFD4');
INSERT INTO color (id, name, code) VALUES (1005,'Azure','#F0FFFF');
INSERT INTO color (id, name, code) VALUES (1006,'Beige','#F5F5DC');
INSERT INTO color (id, name, code) VALUES (1007,'Bisque','#FFE4C4');
INSERT INTO color (id, name, code) VALUES (1008,'Black','#000000');
In [2]:
SELECT * FROM color WHERE name LIKE 'A%';

Autotranslation of results

In [3]:
select * into ${colorTable} from color;
Out[3]:
null
In [8]:
%%javascript
beaker.displayHTML(this, beaker.colorTable.values+"")
Out[8]:
In [ ]:
Autocomplete
In [ ]:
s
In [ ]:
SELECT * FROM color WHE
In [ ]:
INSERT INTO color (id, name, code) VA
In [ ]:
%%beakerDB
In [ ]:
%%