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
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 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|
25 Aytoun Street