563 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owls only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Using T-SQL to create tables programmatically Part one of a four-part series of blogs |
---|
SQL doesn’t just select data; you can also use it to create tables and link them together with relationships. This blog shows you how!
This blog is part of a much longer tutorial on programming in SQL. Alternatively, have a look at our classroom-based training courses in SQL.
|
This blog shows how you can use SQL to create tables. All of the SQL that you'll need will be shown as we go along. Just before we begin, though, let's look at two alternatives to writing SQL code.
It probably goes without saying, but you don't need to write SQL script to create tables:
You can design tables in SQL Server Management Studio (SSMS), specifiying for each column a name and a data type.
If you already have a table, you can use this to generate SQL script:
You can right-click on any table in SSMS and choose to create a new table from it.
This will generate script, which you can then edit as you see fit:
A small part of the script generated by the above menu option.
However, this blog is going to concentrate on writing script from scratch.
If you're wondering why this might be a useful thing to do, SQL works with sets of rows at a time, and it's frequently useful to create ad hoc temporary tables to hold these.
To start with, let's look at how you might first create a database to hold your tables.
Parts of this blog |
---|
|
Some other pages relevant to the above blogs include:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2023. All Rights Reserved.