Microsoft SQL Server/Table manipulation

Introduction
The and  respect the SQL-86 norm. However, in addition to the requests  we find   since the 2008 version.

Create a table
In SSMS, a right click on the folder "Tables" of a database allows to add one.

A right click on a particular table lets choose between:
 * 1) Modify the table structure (add a column, modify a type).
 * 2) Select its 1,000 first records, or the 1,000 last.
 * 3) Edit its 200 first.

Otherwise in SQL one must enter :

Filling the first columns :

To aim some other columns, the fields must be precised. For example, by filling the first name, the last name will be null:

From another table:

Update:

Create an index
The software PK abbreviation means "".

To create a, drop down the table, in the menu Keys, right click, new foreign key..., the list of all the table foreign keys appears in a small window (named by default "FK_..." for "foreign key").

In General, Tables and columns specification, click on "..." to select the table and its field to link.

Add a unique id
Normally each table should own at least one unique id (primary key). However, it's impossible to modify an existing column to attribute the property  needed to such a key.

So to add one:

Copy a table
The selection below clones a table with the same fields sizes:

Knowing that the table  from the system database   contains a sequential field , it becomes possible to generate tables with this counter:

Where: N Line 10 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9

Import a table
From an array ( or ) converted for example in encoded in PC DOS, to import it as a new table :

Delete a table
To delete a whole table (data and structure):

To truncate a table, that is to say to conserve only the headers and columns types, by removing all records:

To delete certain lines from a table:

NB: by adding  before the , we get the deleted content instead of the deleted lines number.}}

Research a table
To research a table which we know the exact name, on all the server databases:

Research in all the tables
SSMS 10 doesn't propose any research function, like one could find it in for MySQL for example.

Table research
This script passes through each database to return the tables which names contain the specified string of characters (at the end):

Research a value
A field value research in all the tables take a few time :