PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Python · Theory

Create database

← All stacks

Theory

113/268

Create database

Create database is about talking to a database from Python. Pattern is always: connect → cursor → execute → fetch or commit → close.

For Create database: use ? placeholders (or the driver’s params). Never build SQL with + user text — that is injection. sqlite3 is in the stdlib for practice; MySQL/Mongo need a driver.

Create database on the board — insert Asha, select her back, print the name. Same idea on MySQL. Close the connection.

Output — database ready. CREATE DATABASE school on MySQL is the same idea.

Exam tip

Steps in order: connect → execute → fetch/commit → close. Mention placeholders.

Example

# Create database
import sqlite3
con = sqlite3.connect(":memory:")
con.execute("attach ':memory:' as school")
print("database ready")
con.close()

Output: database ready. CREATE DATABASE school on MySQL is the same idea.

Short notes

  • DefCreate database uses connect + cursor + SQL/API.
  • RuleCreate database — parameterized queries. Never + user text into SQL.
  • RememberCreate database — commit after write. close when done.
  • TrapCreate database — open connections left hanging; passwords in source.

Questions

1

Explain Create database as if you are teaching a junior — definition, then one tiny script.

2

What does the example print, and why?

3

What mistake do freshers make with Create database?

Previous← DB connectionNextCreate tables →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.