sql example

-- SQL examples ---------------------------------------------------------------------------------------------------

-- http://inf-schule-db.informatik.uni-kl.de/SQLterra1.php --------------------------------------------------------
-- https://www.inf-schule.de/information/datenbanksysteme/terra/relationaledb --------------------------------------
CREATE TABLE `land` (
  `LNR` varchar(4) NOT NULL,
  `Name` varchar(50) NOT NULL,
  `Einwohner` decimal(20,2) DEFAULT NULL,
  `Flaeche` int(11) DEFAULT NULL,
  `Hauptstadt` varchar(30) DEFAULT NULL,
  `Kontinent` varchar(15) DEFAULT NULL,
  `KontinentFlaeche` int(11) DEFAULT NULL,
  `KontinentEinwohner` int(11) NOT NULL
);
-- ----------------------------------------------------------------------------------------------------------------
INSERT INTO `land` (`LNR`, `Name`, `Einwohner`, `Flaeche`, `Hauptstadt`, `Kontinent`, `KontinentFlaeche`, `KontinentEinwohner`) VALUES
('A', 'Österreich', '8.51', 83879, 'Wien', 'Europa', 10, 733),
('AC', 'Antigua und Barbuda', '0.09', 443, 'Saint John s', 'Nordamerika', 24, 523),
('AF', 'Afghanistan', '33.40', 652230, 'Kabul', 'Asien', 44, 4010),
('AG', 'Algerien', '37.40', 2381741, 'Algiers', 'Afrika', 30, 944),
('AL', 'Albanien', '2.80', 28748, 'Tirana', 'Europa', 10, 733);
-- ----------------------------------------------------------------------------------------------------------------
CREATE TABLE `ort` (
  `Name` varchar(30) DEFAULT NULL,
  `Land` varchar(50) NOT NULL,
  `Einwohner` int(11) DEFAULT NULL,
  `Laenge` decimal(10,4) DEFAULT NULL,
  `Breite` decimal(10,4) DEFAULT NULL
);
-- ----------------------------------------------------------------------------------------------------------------
INSERT INTO `ort` (`Name`, `Land`, `Einwohner`, `Laenge`, `Breite`) VALUES
('Kabul', 'Afghanistan', 1400000, '69.0000', '34.0000'),
('Kandahar', 'Afghanistan', 323900, '65.0000', '31.0000'),
('Masar-e Scharif', 'Afghanistan', 250000, '67.0000', '36.0000'),
('Abnub', 'Ägypten', 70791, '31.1500', '27.2700'),
('Abo el Matamer', 'Ägypten', 47432, '30.1800', '30.9200');
-- ----------------------------------------------------------------------------------------------------------------
SELECT name, einwohner, hauptstadt
  FROM land
ORDER BY einwohner DESC
-- ----------------------------------------------------------------------------------------------------------------
SELECT name
  FROM land
WHERE kontinent='europa'
-- ----------------------------------------------------------------------------------------------------------------
SELECT name, einwohner
  FROM land
WHERE einwohner>=10 and einwohner<=100
ORDER BY einwohner DESC
-- ----------------------------------------------------------------------------------------------------------------
SELECT name, hauptstadt
  FROM land
WHERE name LIKE '%Arm%' or name LIKE '%Bein%'
-- ----------------------------------------------------------------------------------------------------------------
SELECT name, laenge
  FROM ort
WHERE land='Deutschland' and laenge<7.768
-- ----------------------------------------------------------------------------------------------------------------
SELECT name, hauptstadt, kontinent
  FROM land
WHERE kontinent IN ('Asien','Australien')

-- https://www.youtube.com/watch?v=91iNR0eG8kE --------------------------------------------------------------------
import mysql.connector
db = mysql.connector.connect(
	host="localhost",
	user="root",
	passwd="root",
	database="testdatabase"
	)
mycurser = db.cursor()
mycursor.execute("CREATE TABLE Person (name VARCHAR(50), age smallint UNSIGNED, personID int PRIMARY KEY AUTO_INCREMENT)")
mycursor.execute("DESCRIBE Person")
mycursor.execute("INSERT INTO Person (name, age) VALUES ('tech with tim', 45)")
mycursor.execute("SELECT * FROM Person")
-- https://www.youtube.com/watch?v=kUBGiABFFHc --------------------------------------------------------------------
import mysql.connector
from datetime import datetime
db = mysql.connector.connect(
	host="localhost",
	user="root",
	passwd="root",
	database="testdatabase"
	)
mycursor = db.cursor()
mycursor.execute("CREATE TABLE Test (name varchar(50) NOT NULL, created datetime NOT NULL, gender ENUM('M', 'F', 'O'), id int PRIMARY KEY NOT NULL AUTO_INCREMENT)")
mycursor.execute("INSERT INTO Test (name, created, gender) VALUES (?,?,?)", ('Tim', datetime.now(), 'M'))
mycursor.execute("SELECT * FROM Test WHERE gender = 'M' ORDER BY id DESC")
mycursor.execute("ALTER TABLE Test ADD COLUMN food VARCHAR(50) NOT NULL")
mycursor.execute("DESCRIBE Test")
mycursor.fetchone()
mycursor.execute("ALTER TABLE Test DROP food")
mycursor.execute("ALTER TABLE Test CHANGE name first_name VARCHAR(50)")
db.commit()

4
8
GERSHWiiN 140 points

                                    SELECT * FROM users;

4 (8 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
examples of sql query sql queries with example example sql database examples SQL examples of sql example of sql database simple sql query examples sql syntax example example of sql query sql example example of query sample data for sql sql examples query example in sql sql sample data sample data sql sql query use examples sql query example sql sample function function sql sample sql statement examples query example of sql query sql with query example sql example queries example sql query example sql sample with SQL sample sql data sql sample sql example sample sql query sample in sql; sql query to select row from table how to select a spisigic value iun sql display in sql average in sql sql command to show rows sql query code example select all records form table sql select column from table select if data is in a table sql iquerry {{}} SQL quire write an sql statement to select all students sample sql &quot;sample.sql&quot; sample.sql sql how to query select random sample sql sample in sql sample sql queries hoe to make seleclt in sql slect from table sql sql sample code sample SQL Querying return sql data by column sql select queries from one tables sql queries select queries of one table sql select statemetn select syntax in sql select columns from db select from &quot;...&quot; select columns with sql select statement sql select all from table column sql query select command in sql example select sql select column sql select all of the rows select particular column in sql query sql database sql query to query table select from table sql query sample sql code example sql statement example select sql example sql select ... select table sql simple select query sql statements examples sql statements SQL SELECT statement which returns all fields select table; select all de un select sql server select sql table select query sql db.query(&quot;select &quot;) select query select from sql select name from table sql Select (SQL) select sql query sql get all rows select where sql select query sql server example sql queries examples query to get column values in sql sql statements example database select query SQL slect select from display record for sql sql query examples sql query sql example query
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source